From b6278f007b1b3927d0e08810c6a6a7b729e553ac Mon Sep 17 00:00:00 2001 From: Jacek Bukarewicz Date: Mon, 1 Sep 2014 11:03:43 +0200 Subject: [PATCH 01/16] Move cynara package to the floor domain This makes cynara conform to the three domain security model according to which program files, libraries and static data associated with the system are given the _ (floor) label. Change-Id: I4279fbe23f37917835257191aaccaef127606788 --- packaging/cynara.manifest | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/cynara.manifest b/packaging/cynara.manifest index f31de52..a76fdba 100644 --- a/packaging/cynara.manifest +++ b/packaging/cynara.manifest @@ -1,5 +1,5 @@ - + -- 2.7.4 From cfa9c8fc022a38c159ce5d2833fa9015144d6329 Mon Sep 17 00:00:00 2001 From: Lukasz Wojciechowski Date: Sat, 30 Aug 2014 23:22:11 +0200 Subject: [PATCH 02/16] Add missing Requires for pre, post and postun scripts in spec And remove unneeded calls to ldconfig in %post and %postun sections of main package as there is no library installed there. Change-Id: I642f9cb073d8dd9b6569d43175a45a40ef51e1bb --- packaging/cynara.spec | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/packaging/cynara.spec b/packaging/cynara.spec index ea556ce..ff98a89 100644 --- a/packaging/cynara.spec +++ b/packaging/cynara.spec @@ -12,6 +12,9 @@ Source1004: cynara-tests.manifest Source1005: libcynara-client-commons.manifest Source1006: libcynara-commons.manifest Requires: default-ac-domains +Requires(pre): pwdutils +Requires(post): smack +Requires(postun): pwdutils BuildRequires: cmake BuildRequires: zip BuildRequires: pkgconfig(libsystemd-daemon) @@ -39,8 +42,6 @@ and tests (cynara-tests) %package -n libcynara-client Summary: Cynara - client library Requires: cynara = %{version}-%{release} -Requires(post): /sbin/ldconfig -Requires(postun): /sbin/ldconfig %description -n libcynara-client client library for checking policies @@ -57,8 +58,6 @@ 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 @@ -74,8 +73,6 @@ client commons library (devel) with common functionalities %package -n libcynara-admin Summary: Cynara - admin client library Requires: cynara = %{version}-%{release} -Requires(post): /sbin/ldconfig -Requires(postun): /sbin/ldconfig %description -n libcynara-admin admin client library for setting, listing and removing policies @@ -91,8 +88,6 @@ 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 @@ -181,8 +176,6 @@ chsmack -a System %{state_path} systemctl restart %{name}.service -/sbin/ldconfig - %preun if [ $1 = 0 ]; then # unistall @@ -196,8 +189,6 @@ if [ $1 = 0 ]; then systemctl daemon-reload fi -/sbin/ldconfig - %post -n libcynara-client -p /sbin/ldconfig %postun -n libcynara-client -p /sbin/ldconfig -- 2.7.4 From 300bb4b003fcf7088a092ada200a2b233babd6ef Mon Sep 17 00:00:00 2001 From: Lukasz Wojciechowski Date: Sat, 30 Aug 2014 23:33:51 +0200 Subject: [PATCH 03/16] Remove not needed %defattr from cynara.spec Change-Id: I96fcb30e5e9a498b69505361150e7b0ffdbebb62 --- packaging/cynara.spec | 4 ---- 1 file changed, 4 deletions(-) diff --git a/packaging/cynara.spec b/packaging/cynara.spec index ff98a89..77759cb 100644 --- a/packaging/cynara.spec +++ b/packaging/cynara.spec @@ -236,11 +236,9 @@ fi %files -n libcynara-client %manifest libcynara-client.manifest %license LICENSE -%defattr(-,root,root,-) %{_libdir}/libcynara-client.so.* %files -n libcynara-client-devel -%defattr(-,root,root,-) %{_includedir}/cynara/cynara-client.h %{_libdir}/pkgconfig/cynara-client.pc %{_libdir}/libcynara-client.so @@ -257,11 +255,9 @@ fi %files -n libcynara-admin %manifest libcynara-admin.manifest %license LICENSE -%defattr(-,root,root,-) %{_libdir}/libcynara-admin.so.* %files -n libcynara-admin-devel -%defattr(-,root,root,-) %{_includedir}/cynara/cynara-admin.h %{_includedir}/cynara/cynara-admin-error.h %{_libdir}/libcynara-admin.so -- 2.7.4 From 5b044e7e7710cab74f74bd33f73386ac3544e81b Mon Sep 17 00:00:00 2001 From: Lukasz Wojciechowski Date: Sun, 31 Aug 2014 03:34:13 +0200 Subject: [PATCH 04/16] Remove -fPIC flag Explicit definition of this flag in not needed. They are added by default when sources are used to create SHARED librray in cmake. Change-Id: I9027835a932b7f46941a5007ddfcce08f85fb38d --- CMakeLists.txt | 5 ----- src/admin/CMakeLists.txt | 2 +- src/common/CMakeLists.txt | 2 +- 3 files changed, 2 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 38c37d7..7fc747b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,11 +36,6 @@ SET(CMAKE_CXX_FLAGS_RELEASE "-g -std=c++0x -O2") SET(CMAKE_C_FLAGS_CCOV "-g -O2 --coverage") SET(CMAKE_CXX_FLAGS_CCOV "-g -std=c++0x -O2 --coverage") -# If supported for the target machine, emit position-independent code,suitable -# for dynamic linking and avoiding any limit on the size of the global offset -# table. This option makes a difference on the m68k, PowerPC and SPARC. -ADD_DEFINITIONS("-fPIC") - # Set compiler warning flags ADD_DEFINITIONS("-Werror") # Make all warnings into errors. ADD_DEFINITIONS("-Wall") # Generate all warnings diff --git a/src/admin/CMakeLists.txt b/src/admin/CMakeLists.txt index 9f53d55..e435d29 100644 --- a/src/admin/CMakeLists.txt +++ b/src/admin/CMakeLists.txt @@ -36,7 +36,7 @@ ADD_LIBRARY(${TARGET_LIB_CYNARA_ADMIN} SHARED ${LIB_CYNARA_ADMIN_SOURCES}) SET_TARGET_PROPERTIES( ${TARGET_LIB_CYNARA_ADMIN} PROPERTIES - COMPILE_FLAGS "-D_GNU_SOURCE -fPIC -fvisibility=hidden" + COMPILE_FLAGS "-D_GNU_SOURCE -fvisibility=hidden" SOVERSION ${LIB_CYNARA_ADMIN_VERSION_MAJOR} VERSION ${LIB_CYNARA_ADMIN_VERSION} ) diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index aef2ae7..3113784 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -58,7 +58,7 @@ ADD_LIBRARY(${TARGET_CYNARA_COMMON} SHARED ${COMMON_SOURCES}) SET_TARGET_PROPERTIES( ${TARGET_CYNARA_COMMON} PROPERTIES - COMPILE_FLAGS "-D_GNU_SOURCE -fPIC -fvisibility=default" + COMPILE_FLAGS "-D_GNU_SOURCE -fvisibility=default" SOVERSION ${CYNARA_COMMON_VERSION_MAJOR} VERSION ${CYNARA_COMMON_VERSION} ) -- 2.7.4 From 21175a334b806bf50f53d4aab1db2c8daa04015f Mon Sep 17 00:00:00 2001 From: Rafal Krypa Date: Mon, 1 Sep 2014 18:34:17 +0200 Subject: [PATCH 05/16] build: rename ambiguous "build" directory to "pkgconfig" Directory supporting generation of package config files was named "build" for no good reason. It was inherited from security-server code base. Change-Id: I17bba90c9de09b2637b50d7d60b436170f3631df Signed-off-by: Rafal Krypa --- CMakeLists.txt | 2 +- {build => pkgconfig}/CMakeLists.txt | 0 {build => pkgconfig}/cynara-admin/CMakeLists.txt | 2 +- {build => pkgconfig}/cynara-admin/cynara-admin.pc.in | 0 {build => pkgconfig}/cynara-client/CMakeLists.txt | 2 +- {build => pkgconfig}/cynara-client/cynara-client.pc.in | 0 6 files changed, 3 insertions(+), 3 deletions(-) rename {build => pkgconfig}/CMakeLists.txt (100%) rename {build => pkgconfig}/cynara-admin/CMakeLists.txt (93%) rename {build => pkgconfig}/cynara-admin/cynara-admin.pc.in (100%) rename {build => pkgconfig}/cynara-client/CMakeLists.txt (93%) rename {build => pkgconfig}/cynara-client/cynara-client.pc.in (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7fc747b..e4da838 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -57,5 +57,5 @@ SET(TARGET_CYNARA_TESTS "cynara-tests") ADD_SUBDIRECTORY(src) ADD_SUBDIRECTORY(test) -ADD_SUBDIRECTORY(build) +ADD_SUBDIRECTORY(pkgconfig) ADD_SUBDIRECTORY(systemd) diff --git a/build/CMakeLists.txt b/pkgconfig/CMakeLists.txt similarity index 100% rename from build/CMakeLists.txt rename to pkgconfig/CMakeLists.txt diff --git a/build/cynara-admin/CMakeLists.txt b/pkgconfig/cynara-admin/CMakeLists.txt similarity index 93% rename from build/cynara-admin/CMakeLists.txt rename to pkgconfig/cynara-admin/CMakeLists.txt index 215d6d7..6adc6b9 100644 --- a/build/cynara-admin/CMakeLists.txt +++ b/pkgconfig/cynara-admin/CMakeLists.txt @@ -20,7 +20,7 @@ CONFIGURE_FILE(cynara-admin.pc.in cynara-admin.pc @ONLY) INSTALL(FILES - ${CMAKE_BINARY_DIR}/build/cynara-admin/cynara-admin.pc + cynara-admin.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig ) diff --git a/build/cynara-admin/cynara-admin.pc.in b/pkgconfig/cynara-admin/cynara-admin.pc.in similarity index 100% rename from build/cynara-admin/cynara-admin.pc.in rename to pkgconfig/cynara-admin/cynara-admin.pc.in diff --git a/build/cynara-client/CMakeLists.txt b/pkgconfig/cynara-client/CMakeLists.txt similarity index 93% rename from build/cynara-client/CMakeLists.txt rename to pkgconfig/cynara-client/CMakeLists.txt index b23c222..ecb78c7 100644 --- a/build/cynara-client/CMakeLists.txt +++ b/pkgconfig/cynara-client/CMakeLists.txt @@ -20,7 +20,7 @@ CONFIGURE_FILE(cynara-client.pc.in cynara-client.pc @ONLY) INSTALL(FILES - ${CMAKE_BINARY_DIR}/build/cynara-client/cynara-client.pc + cynara-client.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig ) diff --git a/build/cynara-client/cynara-client.pc.in b/pkgconfig/cynara-client/cynara-client.pc.in similarity index 100% rename from build/cynara-client/cynara-client.pc.in rename to pkgconfig/cynara-client/cynara-client.pc.in -- 2.7.4 From def3b0096e1e90ba3541037ca668fb5884cae432 Mon Sep 17 00:00:00 2001 From: Rafal Krypa Date: Mon, 1 Sep 2014 18:38:08 +0200 Subject: [PATCH 06/16] build: install systemd files under CMAKE_INSTALL_PREFIX Don't use absolute path for installation of systemd config files. Change-Id: If796cad7a0fdcd32d8179a0de7bc0958f173e35b Signed-off-by: Rafal Krypa --- systemd/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/systemd/CMakeLists.txt b/systemd/CMakeLists.txt index 4076688..8fc27e7 100644 --- a/systemd/CMakeLists.txt +++ b/systemd/CMakeLists.txt @@ -22,6 +22,6 @@ INSTALL(FILES ${CMAKE_SOURCE_DIR}/systemd/cynara.socket ${CMAKE_SOURCE_DIR}/systemd/cynara-admin.socket DESTINATION - /usr/lib/systemd/system + lib/systemd/system ) -- 2.7.4 From b8e1998ecd034e8bf2b028ede186d6a32d7758f9 Mon Sep 17 00:00:00 2001 From: Rafal Krypa Date: Wed, 3 Sep 2014 14:03:02 +0200 Subject: [PATCH 07/16] build: drop D_GNU_SOURCE flag, refactor symbol visibility setting Cynara code doesn't use GNU specific features. There is no need to define _GNU_SOURCE. Also set -fvisibility=hidden by default for all targets and change it only where needed (for building common library). Change-Id: Ie8f46522866b4f475c09b4e6e57f824defed0e5c Signed-off-by: Rafal Krypa --- CMakeLists.txt | 3 +++ src/admin/CMakeLists.txt | 1 - src/client-common/CMakeLists.txt | 3 ++- src/client/CMakeLists.txt | 1 - src/common/CMakeLists.txt | 3 ++- src/service/CMakeLists.txt | 5 ----- 6 files changed, 7 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e4da838..98ae1ae 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -41,6 +41,9 @@ ADD_DEFINITIONS("-Werror") # Make all warnings into errors. ADD_DEFINITIONS("-Wall") # Generate all warnings ADD_DEFINITIONS("-Wextra") # Generate even more extra warnings +# Don't export symbols by default +ADD_DEFINITIONS("-fvisibility=hidden") + STRING(REGEX MATCH "([^.]*)" API_VERSION "${VERSION}") ADD_DEFINITIONS("-DAPI_VERSION=\"$(API_VERSION)\"") diff --git a/src/admin/CMakeLists.txt b/src/admin/CMakeLists.txt index e435d29..cc3d7ac 100644 --- a/src/admin/CMakeLists.txt +++ b/src/admin/CMakeLists.txt @@ -36,7 +36,6 @@ ADD_LIBRARY(${TARGET_LIB_CYNARA_ADMIN} SHARED ${LIB_CYNARA_ADMIN_SOURCES}) SET_TARGET_PROPERTIES( ${TARGET_LIB_CYNARA_ADMIN} PROPERTIES - COMPILE_FLAGS "-D_GNU_SOURCE -fvisibility=hidden" SOVERSION ${LIB_CYNARA_ADMIN_VERSION_MAJOR} VERSION ${LIB_CYNARA_ADMIN_VERSION} ) diff --git a/src/client-common/CMakeLists.txt b/src/client-common/CMakeLists.txt index fdc41c6..dd05c79 100644 --- a/src/client-common/CMakeLists.txt +++ b/src/client-common/CMakeLists.txt @@ -30,12 +30,13 @@ SET(LIB_CYNARA_COMMON_SOURCES ${LIB_CYNARA_COMMON_PATH}/cache/CapacityCache.cpp ) +ADD_DEFINITIONS("-fvisibility=default") + 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} ) diff --git a/src/client/CMakeLists.txt b/src/client/CMakeLists.txt index 09a023e..d364e2d 100644 --- a/src/client/CMakeLists.txt +++ b/src/client/CMakeLists.txt @@ -38,7 +38,6 @@ ADD_LIBRARY(${TARGET_LIB_CYNARA} SHARED ${LIB_CYNARA_SOURCES}) SET_TARGET_PROPERTIES( ${TARGET_LIB_CYNARA} PROPERTIES - COMPILE_FLAGS "-D_GNU_SOURCE -fvisibility=hidden" SOVERSION ${LIB_CYNARA_VERSION_MAJOR} VERSION ${LIB_CYNARA_VERSION} ) diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 3113784..f489b44 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -53,12 +53,13 @@ SET(COMMON_SOURCES ${COMMON_SOURCES} ) ENDIF (CMAKE_BUILD_TYPE MATCHES "DEBUG") +ADD_DEFINITIONS("-fvisibility=default") + ADD_LIBRARY(${TARGET_CYNARA_COMMON} SHARED ${COMMON_SOURCES}) SET_TARGET_PROPERTIES( ${TARGET_CYNARA_COMMON} PROPERTIES - COMPILE_FLAGS "-D_GNU_SOURCE -fvisibility=default" SOVERSION ${CYNARA_COMMON_VERSION_MAJOR} VERSION ${CYNARA_COMMON_VERSION} ) diff --git a/src/service/CMakeLists.txt b/src/service/CMakeLists.txt index 9f11ab8..47482eb 100644 --- a/src/service/CMakeLists.txt +++ b/src/service/CMakeLists.txt @@ -31,11 +31,6 @@ SET(CYNARA_SOURCES ${CYNARA_SERVICE_PATH}/storage/StorageSerializer.cpp ) -SET_SOURCE_FILES_PROPERTIES( - ${CYNARA_SOURCES} - PROPERTIES - COMPILE_FLAGS "-D_GNU_SOURCE -fvisibility=hidden") - INCLUDE_DIRECTORIES( ${CYNARA_SERVICE_PATH} ) -- 2.7.4 From 7b0c554437300f2e836270324786ef54a9d06d94 Mon Sep 17 00:00:00 2001 From: Rafal Krypa Date: Mon, 1 Sep 2014 18:31:04 +0200 Subject: [PATCH 08/16] build: drop unused definition of API_VERSION This is probably copied from some template, but never used. Change-Id: I455bb316b65121ff9ed509884d40c0c14668efce Signed-off-by: Rafal Krypa --- CMakeLists.txt | 2 -- packaging/cynara.spec | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 98ae1ae..c8f1482 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -44,8 +44,6 @@ ADD_DEFINITIONS("-Wextra") # Generate even more extra warni # Don't export symbols by default ADD_DEFINITIONS("-fvisibility=hidden") -STRING(REGEX MATCH "([^.]*)" API_VERSION "${VERSION}") -ADD_DEFINITIONS("-DAPI_VERSION=\"$(API_VERSION)\"") IF (CMAKE_BUILD_TYPE MATCHES "DEBUG") ADD_DEFINITIONS("-DBUILD_TYPE_DEBUG") diff --git a/packaging/cynara.spec b/packaging/cynara.spec index 77759cb..5890e9b 100644 --- a/packaging/cynara.spec +++ b/packaging/cynara.spec @@ -135,7 +135,7 @@ export FFLAGS="$FFLAGS -DTIZEN_DEBUG_ENABLE" export CXXFLAGS="$CXXFLAGS -DCYNARA_STATE_PATH=\\\"%{state_path}\\\"" export LDFLAGS+="-Wl,--rpath=%{_libdir}" -%cmake . -DVERSION=%{version} \ +%cmake . \ -DCMAKE_BUILD_TYPE=%{?build_type} \ -DCMAKE_VERBOSE_MAKEFILE=ON make %{?jobs:-j%jobs} -- 2.7.4 From 2298a060e825301181c7c865424fa1f4ea0abb46 Mon Sep 17 00:00:00 2001 From: Rafal Krypa Date: Tue, 2 Sep 2014 10:48:12 +0200 Subject: [PATCH 09/16] build: clean up settings of compiler flags Compiler flags are set in main CMakeLists.txt. This part of the file looks like a template inherited from other projects and requires some clean up: - drop C flags, there are no C source files. - move fortify flags to spec, they are specific to Tizen build system. - use Cmake built-in features for detection of compiler support for C++11 Change-Id: I40cb76934334c31d7ac59328eed217e08902b187 Signed-off-by: Rafal Krypa --- CMakeLists.txt | 24 ++++++++++++++++-------- packaging/cynara.spec | 6 ++++-- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c8f1482..ab478f9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,17 +24,25 @@ PROJECT("cynara") ############################# cmake packages ################################## INCLUDE(FindPkgConfig) +INCLUDE(CheckCXXCompilerFlag) ############################# compiler flags ################################## -SET(CMAKE_C_FLAGS_PROFILING "-g -O0 -pg") -SET(CMAKE_CXX_FLAGS_PROFILING "-g -std=c++0x -O0 -pg -Wp,-U_FORTIFY_SOURCE") -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(CMAKE_C_FLAGS_CCOV "-g -O2 --coverage") -SET(CMAKE_CXX_FLAGS_CCOV "-g -std=c++0x -O2 --coverage") +SET(CMAKE_CXX_FLAGS_PROFILING "-O0 -g -pg") +SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g -ggdb") +SET(CMAKE_CXX_FLAGS_RELEASE "-O2 -g") +SET(CMAKE_CXX_FLAGS_CCOV "-O2 -g --coverage") + +# Check for C++11 support and enable proper compilation flags +CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11) +CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X) +IF(COMPILER_SUPPORTS_CXX11) + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") +ELSEIF(COMPILER_SUPPORTS_CXX0X) + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x") +ELSE() + MESSAGE(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.") +ENDIF() # Set compiler warning flags ADD_DEFINITIONS("-Werror") # Make all warnings into errors. diff --git a/packaging/cynara.spec b/packaging/cynara.spec index 5890e9b..f2a8d72 100644 --- a/packaging/cynara.spec +++ b/packaging/cynara.spec @@ -127,9 +127,11 @@ cp -a %{SOURCE1006} . %build %if 0%{?sec_build_binary_debug_enable} -export CFLAGS="$CFLAGS -DTIZEN_DEBUG_ENABLE" export CXXFLAGS="$CXXFLAGS -DTIZEN_DEBUG_ENABLE" -export FFLAGS="$FFLAGS -DTIZEN_DEBUG_ENABLE" +%endif + +%if %{?build_type} == "DEBUG" +export CXXFLAGS="$CXXFLAGS -Wp,-U_FORTIFY_SOURCE" %endif export CXXFLAGS="$CXXFLAGS -DCYNARA_STATE_PATH=\\\"%{state_path}\\\"" -- 2.7.4 From 274687f9228b4395c48a359babb73c83a85ba4ca Mon Sep 17 00:00:00 2001 From: Rafal Krypa Date: Mon, 1 Sep 2014 18:49:40 +0200 Subject: [PATCH 10/16] Fix inclusion of libunwind when not building for debug Conditional inclusion of libunwind.h didn't properly depend on definition of BUILD_TYPE_DEBUG. But only debug build checks for libunwind dependency. Change-Id: I2158d09ae2880e9869246d75049aa1f23b8c4bcc Signed-off-by: Rafal Krypa --- src/common/log/Backtrace.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/common/log/Backtrace.h b/src/common/log/Backtrace.h index df023ba..c96f29d 100644 --- a/src/common/log/Backtrace.h +++ b/src/common/log/Backtrace.h @@ -25,7 +25,7 @@ #ifndef SRC_COMMON_LOG_BACKTRACE_H_ #define SRC_COMMON_LOG_BACKTRACE_H_ -#ifndef CYNARA_NO_LOGS +#if defined(BUILD_TYPE_DEBUG) && !defined(CYNARA_NO_LOGS) #define UNW_LOCAL_ONLY #include #endif @@ -53,7 +53,7 @@ private: void operator=(Backtrace const &) = delete; const std::string buildBacktrace(void); -#ifndef CYNARA_NO_LOGS +#if defined(BUILD_TYPE_DEBUG) && !defined(CYNARA_NO_LOGS) void getSourceInfo(unw_word_t proc_address); #endif -- 2.7.4 From aeb36e1cca424466b6e56a38c7b12c71d260d3d9 Mon Sep 17 00:00:00 2001 From: Radoslaw Bartosiak Date: Thu, 14 Aug 2014 13:53:16 +0200 Subject: [PATCH 11/16] Add credential and session helper libraries This change introduces libraries with following functionalities: a) simple session id generation b) user_id and client_id retrieval This patch adds libraries to build and packaging files. There is no code yet - libraries are empty. Change-Id: I4c5c8b75eb5ea4867ba111d936bacbcd41fc5098 --- CMakeLists.txt | 5 + packaging/cynara.spec | 143 ++++++++++++++++++++- packaging/libcynara-creds-commons.manifest | 5 + packaging/libcynara-creds-dbus.manifest | 5 + packaging/libcynara-creds-socket.manifest | 5 + packaging/libcynara-session.manifest | 5 + pkgconfig/CMakeLists.txt | 5 + pkgconfig/cynara-creds-commons/CMakeLists.txt | 26 ++++ .../cynara-creds-commons.pc.in | 11 ++ pkgconfig/cynara-creds-dbus/CMakeLists.txt | 26 ++++ .../cynara-creds-dbus/cynara-creds-dbus.pc.in | 11 ++ pkgconfig/cynara-creds-socket/CMakeLists.txt | 26 ++++ .../cynara-creds-socket/cynara-creds-socket.pc.in | 11 ++ pkgconfig/cynara-session/CMakeLists.txt | 26 ++++ pkgconfig/cynara-session/cynara-session.pc.in | 11 ++ src/CMakeLists.txt | 4 + src/helpers/creds-commons/CMakeLists.txt | 44 +++++++ src/helpers/creds-commons/creds-commons.cpp | 23 ++++ src/helpers/creds-dbus/CMakeLists.txt | 54 ++++++++ src/helpers/creds-dbus/creds-dbus.cpp | 23 ++++ src/helpers/creds-socket/CMakeLists.txt | 44 +++++++ src/helpers/creds-socket/creds-socket.cpp | 23 ++++ src/helpers/session/CMakeLists.txt | 44 +++++++ src/helpers/session/session.cpp | 23 ++++ src/include/CMakeLists.txt | 12 +- src/include/cynara-creds-commons.h | 37 ++++++ src/include/cynara-creds-dbus.h | 37 ++++++ src/include/cynara-creds-socket.h | 37 ++++++ src/include/cynara-session.h | 37 ++++++ 29 files changed, 756 insertions(+), 7 deletions(-) create mode 100644 packaging/libcynara-creds-commons.manifest create mode 100644 packaging/libcynara-creds-dbus.manifest create mode 100644 packaging/libcynara-creds-socket.manifest create mode 100644 packaging/libcynara-session.manifest create mode 100644 pkgconfig/cynara-creds-commons/CMakeLists.txt create mode 100644 pkgconfig/cynara-creds-commons/cynara-creds-commons.pc.in create mode 100644 pkgconfig/cynara-creds-dbus/CMakeLists.txt create mode 100644 pkgconfig/cynara-creds-dbus/cynara-creds-dbus.pc.in create mode 100644 pkgconfig/cynara-creds-socket/CMakeLists.txt create mode 100644 pkgconfig/cynara-creds-socket/cynara-creds-socket.pc.in create mode 100644 pkgconfig/cynara-session/CMakeLists.txt create mode 100644 pkgconfig/cynara-session/cynara-session.pc.in create mode 100644 src/helpers/creds-commons/CMakeLists.txt create mode 100644 src/helpers/creds-commons/creds-commons.cpp create mode 100644 src/helpers/creds-dbus/CMakeLists.txt create mode 100644 src/helpers/creds-dbus/creds-dbus.cpp create mode 100644 src/helpers/creds-socket/CMakeLists.txt create mode 100644 src/helpers/creds-socket/creds-socket.cpp create mode 100644 src/helpers/session/CMakeLists.txt create mode 100644 src/helpers/session/session.cpp create mode 100644 src/include/cynara-creds-commons.h create mode 100644 src/include/cynara-creds-dbus.h create mode 100644 src/include/cynara-creds-socket.h create mode 100644 src/include/cynara-session.h diff --git a/CMakeLists.txt b/CMakeLists.txt index ab478f9..c4f80a2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,6 +14,7 @@ # # @file CMakeLists.txt # @author Lukasz Wojciechowski +# @author Radoslaw Bartosiak # ############################# Check minimum CMake version ##################### @@ -63,6 +64,10 @@ 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") +SET(TARGET_LIB_CREDS_COMMONS "cynara-creds-commons") +SET(TARGET_LIB_CREDS_DBUS "cynara-creds-dbus") +SET(TARGET_LIB_CREDS_SOCKET "cynara-creds-socket") +SET(TARGET_LIB_SESSION "cynara-session") ADD_SUBDIRECTORY(src) ADD_SUBDIRECTORY(test) diff --git a/packaging/cynara.spec b/packaging/cynara.spec index f2a8d72..2036d61 100644 --- a/packaging/cynara.spec +++ b/packaging/cynara.spec @@ -11,6 +11,10 @@ Source1003: libcynara-admin.manifest Source1004: cynara-tests.manifest Source1005: libcynara-client-commons.manifest Source1006: libcynara-commons.manifest +Source1007: libcynara-creds-commons.manifest +Source1008: libcynara-creds-dbus.manifest +Source1009: libcynara-creds-socket.manifest +Source1010: libcynara-session.manifest Requires: default-ac-domains Requires(pre): pwdutils Requires(post): smack @@ -35,7 +39,9 @@ BuildRequires: pkgconfig(libunwind) %endif %description -service, client libraries (libcynara-client, libcynara-admin) +service, client libraries (libcynara-client, libcynara-admin), +helper libraries (libcynara-session, libcynara-creds-common, libcynara-creds-dbus, +libcynara-creds-socket) and tests (cynara-tests) ####################################################### @@ -100,6 +106,65 @@ Requires: libcynara-commons = %{version}-%{release} cynara common library (devel) with common functionalities ####################################################### +%package -n libcynara-creds-commons +Summary: Base library for cynara credentials helpers + +%description -n libcynara-creds-commons +Base library for cynara credentials helpers + +%package -n libcynara-creds-commons-devel +Summary: Base library for cynara credentials helpers (devel) +Requires: libcynara-creds-commons = %{version}-%{release} +Requires: libcynara-client-commons-devel = %{version}-%{release} + +%description -n libcynara-creds-commons-devel +Base library for cynara credentials helpers (devel) + +####################################################### +%package -n libcynara-creds-dbus +Summary: Cynara credentials helpers library for dbus clients +BuildRequires: pkgconfig(dbus-1) +Requires: dbus + +%description -n libcynara-creds-dbus +Cynara credentials helpers library for dbus clients + +%package -n libcynara-creds-dbus-devel +Summary: Cynara credentials helpers library for dbus clients (devel) +Requires: libcynara-creds-dbus = %{version}-%{release} + +%description -n libcynara-creds-dbus-devel +Cynara credentials helpers library for dbus clients (devel) + +####################################################### +%package -n libcynara-creds-socket +Summary: Cynara credentials helpers library for socket clients + +%description -n libcynara-creds-socket +Cynara credentials helpers library for socket clients + +%package -n libcynara-creds-socket-devel +Summary: Cynara credentials helpers library for socket clients (devel) +Requires: libcynara-creds-socket = %{version}-%{release} + +%description -n libcynara-creds-socket-devel +Cynara credentials helpers library for socket clients (devel) + +####################################################### +%package -n libcynara-session +Summary: Cynara helper client session string creation library + +%description -n libcynara-session +Cynara helper client session string creation library + +%package -n libcynara-session-devel +Summary: Cynara helper client session string creation library (devel) +Requires: libcynara-session = %{version}-%{release} + +%description -n libcynara-session-devel +Cynara helper client session string creation library (devel) + +####################################################### %package -n cynara-tests Summary: Cynara - cynara test binaries BuildRequires: pkgconfig(gmock) @@ -124,6 +189,10 @@ cp -a %{SOURCE1003} . cp -a %{SOURCE1004} . cp -a %{SOURCE1005} . cp -a %{SOURCE1006} . +cp -a %{SOURCE1007} . +cp -a %{SOURCE1008} . +cp -a %{SOURCE1009} . +cp -a %{SOURCE1010} . %build %if 0%{?sec_build_binary_debug_enable} @@ -223,6 +292,38 @@ fi %postun -n libcynara-commons-devel -p /sbin/ldconfig +%post -n libcynara-creds-commons -p /sbin/ldconfig + +%postun -n libcynara-creds-commons -p /sbin/ldconfig + +%post -n libcynara-creds-commons-devel -p /sbin/ldconfig + +%postun -n libcynara-creds-commons-devel -p /sbin/ldconfig + +%post -n libcynara-creds-dbus -p /sbin/ldconfig + +%postun -n libcynara-creds-dbus -p /sbin/ldconfig + +%post -n libcynara-creds-dbus-devel -p /sbin/ldconfig + +%postun -n libcynara-creds-dbus-devel -p /sbin/ldconfig + +%post -n libcynara-creds-socket -p /sbin/ldconfig + +%postun -n libcynara-creds-socket -p /sbin/ldconfig + +%post -n libcynara-creds-socket-devel -p /sbin/ldconfig + +%postun -n libcynara-creds-socket-devel -p /sbin/ldconfig + +%post -n libcynara-session -p /sbin/ldconfig + +%postun -n libcynara-session -p /sbin/ldconfig + +%post -n libcynara-session-devel -p /sbin/ldconfig + +%postun -n libcynara-session-devel -p /sbin/ldconfig + %files -n cynara %manifest cynara.manifest %license LICENSE @@ -276,3 +377,43 @@ fi %files -n cynara-tests %manifest cynara-tests.manifest %attr(755,root,root) /usr/bin/cynara-tests + +%files -n libcynara-creds-commons +%manifest libcynara-creds-commons.manifest +%license LICENSE +%{_libdir}/libcynara-creds-commons.so.* + +%files -n libcynara-creds-commons-devel +%{_includedir}/cynara/cynara-creds-commons.h +%{_libdir}/libcynara-creds-commons.so +%{_libdir}/pkgconfig/cynara-creds-commons.pc + +%files -n libcynara-creds-dbus +%manifest libcynara-creds-dbus.manifest +%license LICENSE +%{_libdir}/libcynara-creds-dbus.so.* + +%files -n libcynara-creds-dbus-devel +%{_includedir}/cynara/cynara-creds-dbus.h +%{_libdir}/libcynara-creds-dbus.so +%{_libdir}/pkgconfig/cynara-creds-dbus.pc + +%files -n libcynara-creds-socket +%manifest libcynara-creds-socket.manifest +%license LICENSE +%{_libdir}/libcynara-creds-socket.so.* + +%files -n libcynara-creds-socket-devel +%{_includedir}/cynara/cynara-creds-socket.h +%{_libdir}/libcynara-creds-socket.so +%{_libdir}/pkgconfig/cynara-creds-socket.pc + +%files -n libcynara-session +%manifest libcynara-session.manifest +%license LICENSE +%{_libdir}/libcynara-session.so.* + +%files -n libcynara-session-devel +%{_includedir}/cynara/cynara-session.h +%{_libdir}/libcynara-session.so +%{_libdir}/pkgconfig/cynara-session.pc diff --git a/packaging/libcynara-creds-commons.manifest b/packaging/libcynara-creds-commons.manifest new file mode 100644 index 0000000..a76fdba --- /dev/null +++ b/packaging/libcynara-creds-commons.manifest @@ -0,0 +1,5 @@ + + + + + diff --git a/packaging/libcynara-creds-dbus.manifest b/packaging/libcynara-creds-dbus.manifest new file mode 100644 index 0000000..a76fdba --- /dev/null +++ b/packaging/libcynara-creds-dbus.manifest @@ -0,0 +1,5 @@ + + + + + diff --git a/packaging/libcynara-creds-socket.manifest b/packaging/libcynara-creds-socket.manifest new file mode 100644 index 0000000..a76fdba --- /dev/null +++ b/packaging/libcynara-creds-socket.manifest @@ -0,0 +1,5 @@ + + + + + diff --git a/packaging/libcynara-session.manifest b/packaging/libcynara-session.manifest new file mode 100644 index 0000000..a76fdba --- /dev/null +++ b/packaging/libcynara-session.manifest @@ -0,0 +1,5 @@ + + + + + diff --git a/pkgconfig/CMakeLists.txt b/pkgconfig/CMakeLists.txt index 269b258..0c11631 100644 --- a/pkgconfig/CMakeLists.txt +++ b/pkgconfig/CMakeLists.txt @@ -14,7 +14,12 @@ # # @file CMakeLists.txt # @author Lukasz Wojciechowski +# @author Radoslaw Bartosiak # ADD_SUBDIRECTORY(cynara-client) ADD_SUBDIRECTORY(cynara-admin) +ADD_SUBDIRECTORY(cynara-creds-commons) +ADD_SUBDIRECTORY(cynara-creds-dbus) +ADD_SUBDIRECTORY(cynara-creds-socket) +ADD_SUBDIRECTORY(cynara-session) diff --git a/pkgconfig/cynara-creds-commons/CMakeLists.txt b/pkgconfig/cynara-creds-commons/CMakeLists.txt new file mode 100644 index 0000000..654df6c --- /dev/null +++ b/pkgconfig/cynara-creds-commons/CMakeLists.txt @@ -0,0 +1,26 @@ +# 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 Aleksander Zdyb +# @author Radoslaw Bartosiak +# + +CONFIGURE_FILE(cynara-creds-commons.pc.in cynara-creds-commons.pc @ONLY) + +INSTALL(FILES + ${CMAKE_BINARY_DIR}/pkgconfig/cynara-creds-commons/cynara-creds-commons.pc + DESTINATION + ${LIB_INSTALL_DIR}/pkgconfig + ) diff --git a/pkgconfig/cynara-creds-commons/cynara-creds-commons.pc.in b/pkgconfig/cynara-creds-commons/cynara-creds-commons.pc.in new file mode 100644 index 0000000..cb87e5f --- /dev/null +++ b/pkgconfig/cynara-creds-commons/cynara-creds-commons.pc.in @@ -0,0 +1,11 @@ +prefix=@CMAKE_INSTALL_PREFIX@ +exec_prefix=${prefix} +libdir=@LIB_INSTALL_DIR@ +includedir=${prefix}/include + +Name: cynara-creds-commons +Description: Base package for all cynara-creds packages +Version: 0.0.1 +Requires: +Libs: -L${libdir} -lcynara-creds-commons +Cflags: -I${includedir}/cynara diff --git a/pkgconfig/cynara-creds-dbus/CMakeLists.txt b/pkgconfig/cynara-creds-dbus/CMakeLists.txt new file mode 100644 index 0000000..57c59c9 --- /dev/null +++ b/pkgconfig/cynara-creds-dbus/CMakeLists.txt @@ -0,0 +1,26 @@ +# 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 Aleksander Zdyb +# @author Radoslaw Bartosiak +# + +CONFIGURE_FILE(cynara-creds-dbus.pc.in cynara-creds-dbus.pc @ONLY) + +INSTALL(FILES + ${CMAKE_BINARY_DIR}/pkgconfig/cynara-creds-dbus/cynara-creds-dbus.pc + DESTINATION + ${LIB_INSTALL_DIR}/pkgconfig + ) diff --git a/pkgconfig/cynara-creds-dbus/cynara-creds-dbus.pc.in b/pkgconfig/cynara-creds-dbus/cynara-creds-dbus.pc.in new file mode 100644 index 0000000..296ce6c --- /dev/null +++ b/pkgconfig/cynara-creds-dbus/cynara-creds-dbus.pc.in @@ -0,0 +1,11 @@ +prefix=@CMAKE_INSTALL_PREFIX@ +exec_prefix=${prefix} +libdir=@LIB_INSTALL_DIR@ +includedir=${prefix}/include + +Name: cynara-creds-dbus +Description: cynara-creds package for dbus clients +Version: 0.0.1 +Requires: dbus-1 +Libs: -L${libdir} -lcynara-creds-dbus +Cflags: -I${includedir}/cynara diff --git a/pkgconfig/cynara-creds-socket/CMakeLists.txt b/pkgconfig/cynara-creds-socket/CMakeLists.txt new file mode 100644 index 0000000..504c58c --- /dev/null +++ b/pkgconfig/cynara-creds-socket/CMakeLists.txt @@ -0,0 +1,26 @@ +# 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 Aleksander Zdyb +# @author Radoslaw Bartosiak +# + +CONFIGURE_FILE(cynara-creds-socket.pc.in cynara-creds-socket.pc @ONLY) + +INSTALL(FILES + ${CMAKE_BINARY_DIR}/pkgconfig/cynara-creds-socket/cynara-creds-socket.pc + DESTINATION + ${LIB_INSTALL_DIR}/pkgconfig + ) diff --git a/pkgconfig/cynara-creds-socket/cynara-creds-socket.pc.in b/pkgconfig/cynara-creds-socket/cynara-creds-socket.pc.in new file mode 100644 index 0000000..b81cf68 --- /dev/null +++ b/pkgconfig/cynara-creds-socket/cynara-creds-socket.pc.in @@ -0,0 +1,11 @@ +prefix=@CMAKE_INSTALL_PREFIX@ +exec_prefix=${prefix} +libdir=@LIB_INSTALL_DIR@ +includedir=${prefix}/include + +Name: cynara-creds-socket +Description: cynara-creds package for socket clients +Version: 0.0.1 +Requires: +Libs: -L${libdir} -lcynara-creds-socket +Cflags: -I${includedir}/cynara diff --git a/pkgconfig/cynara-session/CMakeLists.txt b/pkgconfig/cynara-session/CMakeLists.txt new file mode 100644 index 0000000..79ee80d --- /dev/null +++ b/pkgconfig/cynara-session/CMakeLists.txt @@ -0,0 +1,26 @@ +# 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 Aleksander Zdyb +# @author Radoslaw Bartosiak +# + +CONFIGURE_FILE(cynara-session.pc.in cynara-session.pc @ONLY) + +INSTALL(FILES + ${CMAKE_BINARY_DIR}/pkgconfig/cynara-session/cynara-session.pc + DESTINATION + ${LIB_INSTALL_DIR}/pkgconfig + ) diff --git a/pkgconfig/cynara-session/cynara-session.pc.in b/pkgconfig/cynara-session/cynara-session.pc.in new file mode 100644 index 0000000..fa6e763 --- /dev/null +++ b/pkgconfig/cynara-session/cynara-session.pc.in @@ -0,0 +1,11 @@ +prefix=@CMAKE_INSTALL_PREFIX@ +exec_prefix=${prefix} +libdir=@LIB_INSTALL_DIR@ +includedir=${prefix}/include + +Name: cynara-session +Description: cynara-session package +Version: 0.0.1 +Requires: +Libs: -L${libdir} -lcynara-session +Cflags: -I${includedir}/cynara diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 596e84a..2e3e7bf 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -49,3 +49,7 @@ ADD_SUBDIRECTORY(client) ADD_SUBDIRECTORY(client-common) ADD_SUBDIRECTORY(admin) ADD_SUBDIRECTORY(service) +ADD_SUBDIRECTORY(helpers/creds-commons) +ADD_SUBDIRECTORY(helpers/creds-dbus) +ADD_SUBDIRECTORY(helpers/creds-socket) +ADD_SUBDIRECTORY(helpers/session) diff --git a/src/helpers/creds-commons/CMakeLists.txt b/src/helpers/creds-commons/CMakeLists.txt new file mode 100644 index 0000000..00484b7 --- /dev/null +++ b/src/helpers/creds-commons/CMakeLists.txt @@ -0,0 +1,44 @@ +# 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 Aleksander Zdyb +# @author Radoslaw Bartosiak +# @author Lukasz Wojciechowski +# + +SET(LIB_CREDS_COMMONS_VERSION_MAJOR 0) +SET(LIB_CREDS_COMMONS_VERSION ${LIB_CREDS_COMMONS_VERSION_MAJOR}.0.1) + +SET(LIB_CREDS_COMMONS_PATH ${CYNARA_PATH}/helpers/creds-commons) + +SET(LIB_CREDS_COMMONS_SOURCES + ${LIB_CREDS_COMMONS_PATH}/creds-commons.cpp + ) + +INCLUDE_DIRECTORIES( + ${CYNARA_PATH}/include + ${LIB_CREDS_COMMONS_PATH} + ) + +ADD_LIBRARY(${TARGET_LIB_CREDS_COMMONS} SHARED ${LIB_CREDS_COMMONS_SOURCES}) + +SET_TARGET_PROPERTIES( + ${TARGET_LIB_CREDS_COMMONS} + PROPERTIES + SOVERSION ${LIB_CREDS_COMMONS_VERSION_MAJOR} + VERSION ${LIB_CREDS_COMMONS_VERSION} + ) + +INSTALL(TARGETS ${TARGET_LIB_CREDS_COMMONS} DESTINATION ${LIB_INSTALL_DIR}) diff --git a/src/helpers/creds-commons/creds-commons.cpp b/src/helpers/creds-commons/creds-commons.cpp new file mode 100644 index 0000000..4cb7897 --- /dev/null +++ b/src/helpers/creds-commons/creds-commons.cpp @@ -0,0 +1,23 @@ +/* + * 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 creds-commons.cpp + * @author Lukasz Wojciechowski + * @version 1.0 + * @brief Implementation of external libcynara-creds-commons API + */ + +// Empty initial file diff --git a/src/helpers/creds-dbus/CMakeLists.txt b/src/helpers/creds-dbus/CMakeLists.txt new file mode 100644 index 0000000..4e19a8b --- /dev/null +++ b/src/helpers/creds-dbus/CMakeLists.txt @@ -0,0 +1,54 @@ +# 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 Aleksander Zdyb +# @author Radoslaw Bartosiak +# @author Lukasz Wojciechowski +# + +SET(LIB_CREDS_DBUS_VERSION_MAJOR 0) +SET(LIB_CREDS_DBUS_VERSION ${LIB_CREDS_DBUS_VERSION_MAJOR}.0.1) + +SET(LIB_CREDS_DBUS_PATH ${CYNARA_PATH}/helpers/creds-dbus) + +SET(LIB_CREDS_DBUS_SOURCES + ${LIB_CREDS_DBUS_PATH}/creds-dbus.cpp + ) + +PKG_CHECK_MODULES(LIB_CREDS_DBUS_DEP + REQUIRED + dbus-1 + ) + +INCLUDE_DIRECTORIES( + ${CYNARA_PATH}/include + ${LIB_CREDS_DBUS_PATH} + ${LIB_CREDS_DBUS_DEP_INCLUDE_DIRS} + ) + +ADD_LIBRARY(${TARGET_LIB_CREDS_DBUS} SHARED ${LIB_CREDS_DBUS_SOURCES}) + +SET_TARGET_PROPERTIES( + ${TARGET_LIB_CREDS_DBUS} + PROPERTIES + SOVERSION ${LIB_CREDS_DBUS_VERSION_MAJOR} + VERSION ${LIB_CREDS_DBUS_VERSION} + ) + +TARGET_LINK_LIBRARIES(${TARGET_LIB_CREDS_DBUS} + ${LIB_CREDS_DBUS_DEP_LIBRARIES} + ) + +INSTALL(TARGETS ${TARGET_LIB_CREDS_DBUS} DESTINATION ${LIB_INSTALL_DIR}) diff --git a/src/helpers/creds-dbus/creds-dbus.cpp b/src/helpers/creds-dbus/creds-dbus.cpp new file mode 100644 index 0000000..535ca84 --- /dev/null +++ b/src/helpers/creds-dbus/creds-dbus.cpp @@ -0,0 +1,23 @@ +/* + * 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 creds-dbus.cpp + * @author Lukasz Wojciechowski + * @version 1.0 + * @brief Implementation of external libcynara-creds-dbus API + */ + +// Empty initial file diff --git a/src/helpers/creds-socket/CMakeLists.txt b/src/helpers/creds-socket/CMakeLists.txt new file mode 100644 index 0000000..c42e94d --- /dev/null +++ b/src/helpers/creds-socket/CMakeLists.txt @@ -0,0 +1,44 @@ +# 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 Aleksander Zdyb +# @author Radoslaw Bartosiak +# @author Lukasz Wojciechowski +# + +SET(LIB_CREDS_SOCKET_VERSION_MAJOR 0) +SET(LIB_CREDS_SOCKET_VERSION ${LIB_CREDS_SOCKET_VERSION_MAJOR}.0.1) + +SET(LIB_CREDS_SOCKET_PATH ${CYNARA_PATH}/helpers/creds-socket) + +SET(LIB_CREDS_SOCKET_SOURCES + ${LIB_CREDS_SOCKET_PATH}/creds-socket.cpp + ) + +INCLUDE_DIRECTORIES( + ${CYNARA_PATH}/include + ${LIB_CREDS_SOCKET_PATH} + ) + +ADD_LIBRARY(${TARGET_LIB_CREDS_SOCKET} SHARED ${LIB_CREDS_SOCKET_SOURCES}) + +SET_TARGET_PROPERTIES( + ${TARGET_LIB_CREDS_SOCKET} + PROPERTIES + SOVERSION ${LIB_CREDS_SOCKET_VERSION_MAJOR} + VERSION ${LIB_CREDS_SOCKET_VERSION} + ) + +INSTALL(TARGETS ${TARGET_LIB_CREDS_SOCKET} DESTINATION ${LIB_INSTALL_DIR}) diff --git a/src/helpers/creds-socket/creds-socket.cpp b/src/helpers/creds-socket/creds-socket.cpp new file mode 100644 index 0000000..0ee2661 --- /dev/null +++ b/src/helpers/creds-socket/creds-socket.cpp @@ -0,0 +1,23 @@ +/* + * 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 creds-socket.cpp + * @author Lukasz Wojciechowski + * @version 1.0 + * @brief Implementation of external libcynara-creds-socket API + */ + +// Empty initial file diff --git a/src/helpers/session/CMakeLists.txt b/src/helpers/session/CMakeLists.txt new file mode 100644 index 0000000..b019f4c --- /dev/null +++ b/src/helpers/session/CMakeLists.txt @@ -0,0 +1,44 @@ +# 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 Aleksander Zdyb +# @author Radoslaw Bartosiak +# @author Lukasz Wojciechowski +# + +SET(LIB_SESSION_VERSION_MAJOR 0) +SET(LIB_SESSION_VERSION ${LIB_SESSION_VERSION_MAJOR}.0.1) + +SET(LIB_SESSION_PATH ${CYNARA_PATH}/helpers/session) + +SET(LIB_SESSION_SOURCES + ${LIB_SESSION_PATH}/session.cpp + ) + +INCLUDE_DIRECTORIES( + ${CYNARA_PATH}/include + ${LIB_SESSION_PATH} + ) + +ADD_LIBRARY(${TARGET_LIB_SESSION} SHARED ${LIB_SESSION_SOURCES}) + +SET_TARGET_PROPERTIES( + ${TARGET_LIB_SESSION} + PROPERTIES + SOVERSION ${LIB_SESSION_VERSION_MAJOR} + VERSION ${LIB_SESSION_VERSION} + ) + +INSTALL(TARGETS ${TARGET_LIB_SESSION} DESTINATION ${LIB_INSTALL_DIR}) diff --git a/src/helpers/session/session.cpp b/src/helpers/session/session.cpp new file mode 100644 index 0000000..f65f23b --- /dev/null +++ b/src/helpers/session/session.cpp @@ -0,0 +1,23 @@ +/* + * 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 session.cpp + * @author Lukasz Wojciechowski + * @version 1.0 + * @brief Implementation of external libcynara-session API + */ + +// Empty initial file diff --git a/src/include/CMakeLists.txt b/src/include/CMakeLists.txt index 486f657..261c34d 100644 --- a/src/include/CMakeLists.txt +++ b/src/include/CMakeLists.txt @@ -17,13 +17,13 @@ # 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 + ${CYNARA_PATH}/include/cynara-client.h + ${CYNARA_PATH}/include/cynara-client-error.h + ${CYNARA_PATH}/include/cynara-creds-commons.h + ${CYNARA_PATH}/include/cynara-creds-dbus.h + ${CYNARA_PATH}/include/cynara-creds-socket.h + ${CYNARA_PATH}/include/cynara-session.h DESTINATION ${INCLUDE_INSTALL_DIR}/cynara ) diff --git a/src/include/cynara-creds-commons.h b/src/include/cynara-creds-commons.h new file mode 100644 index 0000000..655dbac --- /dev/null +++ b/src/include/cynara-creds-commons.h @@ -0,0 +1,37 @@ +/* + * 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-creds-commons.h + * @author Lukasz Wojciechowski + * @version 1.0 + * @brief This file contains common APIs for Cynara credentials helper. + */ + + +#ifndef CYNARA_CREDS_COMMONS_H +#define CYNARA_CREDS_COMMONS_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* empty initial file */ + +#ifdef __cplusplus +} +#endif + +#endif /* CYNARA_CREDS_COMMONS_H */ diff --git a/src/include/cynara-creds-dbus.h b/src/include/cynara-creds-dbus.h new file mode 100644 index 0000000..925a829 --- /dev/null +++ b/src/include/cynara-creds-dbus.h @@ -0,0 +1,37 @@ +/* + * 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-creds-dbus.h + * @author Lukasz Wojciechowski + * @version 1.0 + * @brief This file contains Cynara credentials helper APIs for dbus clients. + */ + + +#ifndef CYNARA_CREDS_DBUS_H +#define CYNARA_CREDS_DBUS_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* empty initial file */ + +#ifdef __cplusplus +} +#endif + +#endif /* CYNARA_CREDS_DBUS_H */ diff --git a/src/include/cynara-creds-socket.h b/src/include/cynara-creds-socket.h new file mode 100644 index 0000000..bc89684 --- /dev/null +++ b/src/include/cynara-creds-socket.h @@ -0,0 +1,37 @@ +/* + * 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-creds-socket.h + * @author Lukasz Wojciechowski + * @version 1.0 + * @brief This file contains Cynara credentials helper APIs for socket clients. + */ + + +#ifndef CYNARA_CREDS_SOCKET_H +#define CYNARA_CREDS_SOCKET_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* empty initial file */ + +#ifdef __cplusplus +} +#endif + +#endif /* CYNARA_CREDS_SOCKET_H */ diff --git a/src/include/cynara-session.h b/src/include/cynara-session.h new file mode 100644 index 0000000..ab96e0b --- /dev/null +++ b/src/include/cynara-session.h @@ -0,0 +1,37 @@ +/* + * 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-session.h + * @author Lukasz Wojciechowski + * @version 1.0 + * @brief This file contains Cynara session helper APIs. + */ + + +#ifndef CYNARA_SESSION_H +#define CYNARA_SESSION_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* empty initial file */ + +#ifdef __cplusplus +} +#endif + +#endif /* CYNARA_SESSION_H */ -- 2.7.4 From b77fd803be77217292ba941f59fa40225b72f3e1 Mon Sep 17 00:00:00 2001 From: Radoslaw Bartosiak Date: Wed, 3 Sep 2014 21:13:03 +0200 Subject: [PATCH 12/16] Implement cynara-session library Change-Id: I929408dc59db5f4ab115567fd4839258bd086418 --- src/helpers/session/session.cpp | 22 +++++++++++++- src/include/cynara-session.h | 64 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 84 insertions(+), 2 deletions(-) diff --git a/src/helpers/session/session.cpp b/src/helpers/session/session.cpp index f65f23b..8c94868 100644 --- a/src/helpers/session/session.cpp +++ b/src/helpers/session/session.cpp @@ -15,9 +15,29 @@ */ /* * @file session.cpp + * @author Radoslaw Bartosiak + * @author Aleksander Zdyb * @author Lukasz Wojciechowski * @version 1.0 * @brief Implementation of external libcynara-session API */ -// Empty initial file +#include +#include +#include + +#include + +#include + +CYNARA_API +char *cynara_session_from_pid(pid_t client_pid) { + std::string path = std::string("/proc/") + std::to_string(client_pid); + + struct stat st; + if (stat(path.c_str(), &st) < 0) + return nullptr; + + std::string session = std::to_string(st.st_ctim.tv_sec) + path; + return strdup(session.c_str()); +} diff --git a/src/include/cynara-session.h b/src/include/cynara-session.h index ab96e0b..d24c57d 100644 --- a/src/include/cynara-session.h +++ b/src/include/cynara-session.h @@ -15,6 +15,8 @@ */ /* * @file cynara-session.h + * \author Aleksander Zdyb + * \author Radoslaw Bartosiak * @author Lukasz Wojciechowski * @version 1.0 * @brief This file contains Cynara session helper APIs. @@ -24,11 +26,71 @@ #ifndef CYNARA_SESSION_H #define CYNARA_SESSION_H +#include + #ifdef __cplusplus extern "C" { #endif -/* empty initial file */ +/** + * \par Description: + * Creates a client session string based on pid and time of creation of client process + * + * \par Purpose: + * This function can be used to create session string identifier used in cynara_check() + * and cynara_async_check() functions defined in client libraries. + * + * \par Typical use case: + * The function is called before the call of one of ...check() functions. + * Returned string is used as client_session param in ...check() function. + * String is released with free() function. + * + * \par Method of function operation: + * The function generates client session based on the pid and start time of the client process. + * Time is acquired from /proc/PID directory. + * + * \par Sync (or) Async: + * This is a synchronous API. + * + * \par Thread safety: + * This function is thread-safe. + * + * \par Important notes: + * Memory for returned string is obtained with malloc(), and should be freed with free(). + * + * \param[in] client_pid client application process identifier (PID). + * + * \return session string on success + * or NULL on error. + */ +char *cynara_session_from_pid(pid_t client_pid); + +/* //sample code + * + * (...) + * + * //create client session + * char *client_session; + * client_session = cynara_session_from_pid(client_pid); + * if (!client_session) { + * //use another way to create session or abandon request sending + * } + * + * //check access (details of this function can be found in cynara-client.h) + * int ret = cynara_check(p_cynara, client, client_session, user, privilege); + * + * //release client_session memory + * free(client_session); + * + * //handle check answer + * if (ret < 0) { + * //handle error + * } else { + * //handle response + * } + * + * (...) + */ #ifdef __cplusplus } -- 2.7.4 From f9a46cb7e26c340cc779f86947895b3b33bc7453 Mon Sep 17 00:00:00 2001 From: Radoslaw Bartosiak Date: Sun, 31 Aug 2014 10:22:44 +0200 Subject: [PATCH 13/16] Add new error codes needed by credential helpers Added codes are: CYNARA_API_METHOD_NOT_SUPPORTED CYNARA_API_UNKNOWN_ERROR Change-Id: I604ce30b37bdfe4ecba637bcf423e6fea0b2610c --- src/include/cynara-client-error.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/include/cynara-client-error.h b/src/include/cynara-client-error.h index e5539ea..a506762 100644 --- a/src/include/cynara-client-error.h +++ b/src/include/cynara-client-error.h @@ -48,6 +48,12 @@ /*! \brief indicating that value is not present in cache */ #define CYNARA_API_CACHE_MISS -5 + +/*! \brief indicating that provided method is not supported by library */ +#define CYNARA_API_METHOD_NOT_SUPPORTED -6 + +/*! \brief indicating an unknown error */ +#define CYNARA_API_UNKNOWN_ERROR -7 /** @}*/ #endif // CYNARA_CLIENT_ERROR_H -- 2.7.4 From 7558b9540b6c51b9822c63bbbdf42da282b1a7c1 Mon Sep 17 00:00:00 2001 From: Radoslaw Bartosiak Date: Wed, 3 Sep 2014 21:23:56 +0200 Subject: [PATCH 14/16] Add enums for credentials acquire methods Change-Id: I5719a7622a78ae6d1ca86a7dcce986c69abb3e23 --- src/include/cynara-creds-commons.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/include/cynara-creds-commons.h b/src/include/cynara-creds-commons.h index 655dbac..9f012e1 100644 --- a/src/include/cynara-creds-commons.h +++ b/src/include/cynara-creds-commons.h @@ -16,6 +16,8 @@ /* * @file cynara-creds-commons.h * @author Lukasz Wojciechowski + * @author Radoslaw Bartosiak + * @author Aleksander Zdyb * @version 1.0 * @brief This file contains common APIs for Cynara credentials helper. */ @@ -24,6 +26,16 @@ #ifndef CYNARA_CREDS_COMMONS_H #define CYNARA_CREDS_COMMONS_H +enum cynara_client_creds { + CLIENT_METHOD_SMACK, + CLIENT_METHOD_PID +}; + +enum cynara_user_creds { + USER_METHOD_UID, + USER_METHOD_GID +}; + #ifdef __cplusplus extern "C" { #endif -- 2.7.4 From d9db2d3f62949613cf7523f77f40d415e051af3d Mon Sep 17 00:00:00 2001 From: Radoslaw Bartosiak Date: Wed, 3 Sep 2014 21:13:03 +0200 Subject: [PATCH 15/16] Implement cynara-creds-socket library Change-Id: Ifa27c49c3361547c75d50aa7cbf72e4bd3648201 --- src/helpers/creds-socket/CMakeLists.txt | 1 + src/helpers/creds-socket/creds-socket-inner.cpp | 113 +++++++++++++++++++++++ src/helpers/creds-socket/creds-socket-inner.h | 41 +++++++++ src/helpers/creds-socket/creds-socket.cpp | 48 +++++++++- src/include/cynara-creds-socket.h | 115 +++++++++++++++++++++++- 5 files changed, 316 insertions(+), 2 deletions(-) create mode 100644 src/helpers/creds-socket/creds-socket-inner.cpp create mode 100644 src/helpers/creds-socket/creds-socket-inner.h diff --git a/src/helpers/creds-socket/CMakeLists.txt b/src/helpers/creds-socket/CMakeLists.txt index c42e94d..a425c0b 100644 --- a/src/helpers/creds-socket/CMakeLists.txt +++ b/src/helpers/creds-socket/CMakeLists.txt @@ -25,6 +25,7 @@ SET(LIB_CREDS_SOCKET_PATH ${CYNARA_PATH}/helpers/creds-socket) SET(LIB_CREDS_SOCKET_SOURCES ${LIB_CREDS_SOCKET_PATH}/creds-socket.cpp + ${LIB_CREDS_SOCKET_PATH}/creds-socket-inner.cpp ) INCLUDE_DIRECTORIES( diff --git a/src/helpers/creds-socket/creds-socket-inner.cpp b/src/helpers/creds-socket/creds-socket-inner.cpp new file mode 100644 index 0000000..a227e5b --- /dev/null +++ b/src/helpers/creds-socket/creds-socket-inner.cpp @@ -0,0 +1,113 @@ +/* + * 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 creds-socket-inner.cpp + * @author Radoslaw Bartosiak + * @author Aleksander Zdyb + * @author Lukasz Wojciechowski + * @version 1.0 + * @brief Implementation of internal libcynara-creds-socket functions + */ + + +#include +#include +#include + +#include +#include + +#include + +#include "creds-socket-inner.h" + +int getClientSmackLabel(int socketFd, char **client) { + char dummy; + int ret; + socklen_t length = 1; + char *result; + + ret = getsockopt(socketFd, SOL_SOCKET, SO_PEERSEC, &dummy, &length); + if ((ret < 0) && (errno != ERANGE)) + return CYNARA_API_INVALID_PARAM; + + result = static_cast(calloc(length + 1, sizeof(char))); + if (result == nullptr) + return CYNARA_API_OUT_OF_MEMORY; + + ret = getsockopt(socketFd, SOL_SOCKET, SO_PEERSEC, result, &length); + if (ret < 0) { + free(result); + return CYNARA_API_INVALID_PARAM; + } + + *client = result; + return CYNARA_API_SUCCESS; +} + +#define GET_CRED(SOCK, RESULT, CRED) \ + struct ucred credentials; \ + int ret = getCredentials(SOCK, &credentials); \ + if (ret < 0) \ + return ret; \ + \ + *RESULT = strdup(std::to_string(credentials.CRED).c_str()); \ + if (*RESULT == nullptr) \ + return CYNARA_API_OUT_OF_MEMORY; \ + \ + return CYNARA_API_SUCCESS; \ + +int getClientPid(int socketFd, char **client) { + GET_CRED(socketFd, client, pid) +} + +int getUserId(int socketFd, char **user) { + GET_CRED(socketFd, user, uid) +} + +int getUserGid(int socketFd, char **user) { + GET_CRED(socketFd, user, gid) +} + +int getCredentials(int socketFd, struct ucred *credentials) { + if (credentials == nullptr) + return CYNARA_API_UNKNOWN_ERROR; + + int ret; + socklen_t length = sizeof(struct ucred); + ret = getsockopt(socketFd, SOL_SOCKET, SO_PEERCRED, credentials, &length); + if (ret < 0) { + switch (errno) { + case EBADF: + case ENOTSOCK: + return CYNARA_API_INVALID_PARAM; + default: + return CYNARA_API_UNKNOWN_ERROR; + } + } + return CYNARA_API_SUCCESS; +} + +int getPid(int socketFd, pid_t *pid) { + struct ucred credentials; + int ret = getCredentials(socketFd, &credentials); + if (ret < 0) + return ret; + + *pid = credentials.pid; + + return CYNARA_API_SUCCESS; +} diff --git a/src/helpers/creds-socket/creds-socket-inner.h b/src/helpers/creds-socket/creds-socket-inner.h new file mode 100644 index 0000000..3edb151 --- /dev/null +++ b/src/helpers/creds-socket/creds-socket-inner.h @@ -0,0 +1,41 @@ +/* + * 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 creds-socket-inner.h + * @author Radoslaw Bartosiak + * @author Aleksander Zdyb + * @author Lukasz Wojciechowski + * @version 1.0 + * @brief Definition of internal external libcynara-creds-socket functions + */ + +#ifndef SRC_HELPERS_CREDSSOCKET_CREDSSOCKETINNER_H_ +#define SRC_HELPERS_CREDSSOCKET_CREDSSOCKETINNER_H_ + +#include +#include + +int getClientSmackLabel(int socketFd, char **client); + +int getClientPid(int socketFd, char **client); +int getUserId(int socketFd, char **user); +int getUserGid(int socketFd, char **user); + +int getCredentials(int socketFd, struct ucred *credentials); + +int getPid(int socketFd, pid_t *pid); + +#endif /* SRC_HELPERS_CREDSSOCKET_CREDSSOCKETINNER_H_ */ diff --git a/src/helpers/creds-socket/creds-socket.cpp b/src/helpers/creds-socket/creds-socket.cpp index 0ee2661..a135f87 100644 --- a/src/helpers/creds-socket/creds-socket.cpp +++ b/src/helpers/creds-socket/creds-socket.cpp @@ -15,9 +15,55 @@ */ /* * @file creds-socket.cpp + * @author Radoslaw Bartosiak + * @author Aleksander Zdyb * @author Lukasz Wojciechowski * @version 1.0 * @brief Implementation of external libcynara-creds-socket API */ -// Empty initial file +#include +#include + +#include + +#include + +#include +#include +#include + +CYNARA_API +int cynara_creds_socket_get_client(int socket_fd, enum cynara_client_creds method, char **client) { + if (client == nullptr) + return CYNARA_API_INVALID_PARAM; + + switch (method) { + case cynara_client_creds::CLIENT_METHOD_SMACK: + return getClientSmackLabel(socket_fd, client); + case cynara_client_creds::CLIENT_METHOD_PID: + return getClientPid(socket_fd, client); + default: + return CYNARA_API_METHOD_NOT_SUPPORTED; + } +} + +CYNARA_API +int cynara_creds_socket_get_user(int socket_fd, enum cynara_user_creds method, char **user) { + if (user == nullptr) + return CYNARA_API_INVALID_PARAM; + + switch (method) { + case cynara_user_creds::USER_METHOD_UID: + return getUserId(socket_fd, user); + case cynara_user_creds::USER_METHOD_GID: + return getUserGid(socket_fd, user); + default: + return CYNARA_API_METHOD_NOT_SUPPORTED; + } +} + +CYNARA_API +int cynara_creds_socket_get_pid(int socket_fd, pid_t *pid) { + return getPid(socket_fd, pid); +} diff --git a/src/include/cynara-creds-socket.h b/src/include/cynara-creds-socket.h index bc89684..1b6c09e 100644 --- a/src/include/cynara-creds-socket.h +++ b/src/include/cynara-creds-socket.h @@ -15,6 +15,8 @@ */ /* * @file cynara-creds-socket.h + * @author Radoslaw Bartosiak + * @author Aleksander Zdyb * @author Lukasz Wojciechowski * @version 1.0 * @brief This file contains Cynara credentials helper APIs for socket clients. @@ -24,11 +26,122 @@ #ifndef CYNARA_CREDS_SOCKET_H #define CYNARA_CREDS_SOCKET_H +#include + +#include "cynara-creds-commons.h" + #ifdef __cplusplus extern "C" { #endif -/* empty initial file */ +/** + * \par Description: + * Creates a client identification string with given method. Client is a process at the other + * side of socket. + * + * \par Purpose: + * Client identification string is required for cynara_check() and cynara_async_check() functions. + * + * \par Typical use case: + * The function is called before the call of one of ...check() functions. + * Returned string is used as client parameter in ...check() function. + * String is released with free() function when it is no longer needed. + * + * \par Method of function operation: + * The function generates client string using SO_PEERCRED on socket. + * + * \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 mutex protected critical section. + * + * \par Important notes: + * Memory for returned client string is obtained with malloc(), and should be freed with free(). + * Allocated string is returned only, when function succeeds. + * + * \param[in] socket_fd Descriptor of open connected UNIX socket + * \param[in] method Method of client identifier creation + * \param[out] client Placeholder for allocated string containing client id + * + * \return CYNARA_API_SUCCESS on success + * CYNARA_API_INVALID_PARAM when client is NULL or socket_fd is not valid connected socket + * descriptor + * CYNARA_API_METHOD_NOT_SUPPORTED when requested method is not supported + * CYNARA_API_OUT_OF_MEMORY when there was error allocating memory + */ +int cynara_creds_socket_get_client(int socket_fd, enum cynara_client_creds method, char **client); + +/** + * \par Description: + * Creates a user identification string with given method. User is an executor of process + * at the other side of socket. + * + * \par Purpose: + * User identification string is required for cynara_check() and cynara_async_check() functions. + * + * \par Typical use case: + * The function is called before the call of one of ...check() functions. + * Returned string is used as user parameter in ...check() function. + * String is released with free() function when it is no longer needed. + * + * \par Method of function operation: + * The function generates user string using SO_PEERCRED on socket. + * + * \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 mutex protected critical section. + * + * \par Important notes: + * Memory for returned user string is obtained with malloc(), and should be freed with free(). + * Allocated string is returned only, when function succeeds. + * + * \param[in] socket_fd Descriptor of open connected UNIX socket + * \param[in] method Method of user identifier creation + * \param[out] user Placeholder for allocated string containing user id + * + * \return CYNARA_API_SUCCESS on success + * CYNARA_API_INVALID_PARAM when user is NULL or socket_fd is not valid connected socket + * descriptor + * CYNARA_API_METHOD_NOT_SUPPORTED when requested method is not supported + * CYNARA_API_OUT_OF_MEMORY when there was error allocating memory + */ +int cynara_creds_socket_get_user(int socket_fd, enum cynara_user_creds method, char **user); + +/** + * \par Description: + * Return PID of process at the other side of socket. + * + * \par Purpose: + * PID may be used for client_session creation with cynara_session_from_pid() function + * from libcynara-session library. Client_session is needed for cynara_check() + * and cynara_async_check() functions. + * + * \par Typical use case: + * The function is called before the call of cynara_session_from_pid() function. + * + * \par Method of function operation: + * The function reads PID of peer using SO_PEERCRED on socket. + * + * \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 mutex protected critical section. + * + * \param[in] socket_fd Descriptor of open connected UNIX socket + * \param[out] pid Placeholder for pid + * + * \return CYNARA_API_SUCCESS on success + * CYNARA_API_INVALID_PARAM when socket_fd is not valid connected socket descriptor + * CYNARA_API_UNKNOWN_ERROR when system function fails in incredible situation + */ +int cynara_creds_socket_get_pid(int socket_fd, pid_t *pid); #ifdef __cplusplus } -- 2.7.4 From a41af0d1e2a95773389dcf6a67c2213b1e6debc1 Mon Sep 17 00:00:00 2001 From: Radoslaw Bartosiak Date: Wed, 3 Sep 2014 21:48:25 +0200 Subject: [PATCH 16/16] Prepare libcynara-creds-dbus for implementation Change-Id: Ibdecf8790b7d296e35c063c52202a4a672ad9e9a --- src/helpers/creds-dbus/CMakeLists.txt | 1 + src/helpers/creds-dbus/creds-dbus-inner.cpp | 58 +++++++++++++ src/helpers/creds-dbus/creds-dbus-inner.h | 39 +++++++++ src/helpers/creds-dbus/creds-dbus.cpp | 51 +++++++++++- src/include/cynara-creds-dbus.h | 125 +++++++++++++++++++++++++++- 5 files changed, 272 insertions(+), 2 deletions(-) create mode 100644 src/helpers/creds-dbus/creds-dbus-inner.cpp create mode 100644 src/helpers/creds-dbus/creds-dbus-inner.h diff --git a/src/helpers/creds-dbus/CMakeLists.txt b/src/helpers/creds-dbus/CMakeLists.txt index 4e19a8b..c80d301 100644 --- a/src/helpers/creds-dbus/CMakeLists.txt +++ b/src/helpers/creds-dbus/CMakeLists.txt @@ -25,6 +25,7 @@ SET(LIB_CREDS_DBUS_PATH ${CYNARA_PATH}/helpers/creds-dbus) SET(LIB_CREDS_DBUS_SOURCES ${LIB_CREDS_DBUS_PATH}/creds-dbus.cpp + ${LIB_CREDS_DBUS_PATH}/creds-dbus-inner.cpp ) PKG_CHECK_MODULES(LIB_CREDS_DBUS_DEP diff --git a/src/helpers/creds-dbus/creds-dbus-inner.cpp b/src/helpers/creds-dbus/creds-dbus-inner.cpp new file mode 100644 index 0000000..f72f073 --- /dev/null +++ b/src/helpers/creds-dbus/creds-dbus-inner.cpp @@ -0,0 +1,58 @@ +/* + * 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 creds-dbus-inner.cpp + * @author Radoslaw Bartosiak + * @author Aleksander Zdyb + * @author Lukasz Wojciechowski + * @version 1.0 + * @brief Implementation of internal libcynara-creds-dbus functions + */ + +#include + +#include + +#include "creds-dbus-inner.h" + +int getClientSmackLabel(DBusConnection *connection UNUSED, const char *uniqueName UNUSED, + char **client UNUSED) { + //todo + return CYNARA_API_METHOD_NOT_SUPPORTED; +} + +int getClientPid(DBusConnection *connection UNUSED, const char *uniqueName UNUSED, + char **client UNUSED) { + //todo + return CYNARA_API_METHOD_NOT_SUPPORTED; +} + +int getUserId(DBusConnection *connection UNUSED, const char *uniqueName UNUSED, + char **user UNUSED) { + //todo + return CYNARA_API_METHOD_NOT_SUPPORTED; +} + +int getUserGid(DBusConnection *connection UNUSED, const char *uniqueName UNUSED, + char **user UNUSED) { + //todo + return CYNARA_API_METHOD_NOT_SUPPORTED; +} + +int getPid(DBusConnection *connection UNUSED, const char *uniqueName UNUSED, pid_t *pid UNUSED) { + //todo + return CYNARA_API_METHOD_NOT_SUPPORTED; +} diff --git a/src/helpers/creds-dbus/creds-dbus-inner.h b/src/helpers/creds-dbus/creds-dbus-inner.h new file mode 100644 index 0000000..4c51119 --- /dev/null +++ b/src/helpers/creds-dbus/creds-dbus-inner.h @@ -0,0 +1,39 @@ +/* + * 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 creds-dbus-inner.h + * @author Radoslaw Bartosiak + * @author Aleksander Zdyb + * @author Lukasz Wojciechowski + * @version 1.0 + * @brief Definition of internal external libcynara-creds-dbus functions + */ + +#ifndef SRC_HELPERS_CREDSDBUS_CREDSDBUSINNER_H_ +#define SRC_HELPERS_CREDSDBUS_CREDSDBUSINNER_H_ + +#include +#include + +int getClientSmackLabel(DBusConnection *connection, const char *uniqueName, char **client); +int getClientPid(DBusConnection *connection, const char *uniqueName, char **client); + +int getUserId(DBusConnection *connection, const char *uniqueName, char **user); +int getUserGid(DBusConnection *connection, const char *uniqueName, char **user); + +int getPid(DBusConnection *connection, const char *uniqueName, pid_t *pid); + +#endif /* SRC_HELPERS_CREDSDBUS_CREDSDBUSINNER_H_ */ diff --git a/src/helpers/creds-dbus/creds-dbus.cpp b/src/helpers/creds-dbus/creds-dbus.cpp index 535ca84..344cd02 100644 --- a/src/helpers/creds-dbus/creds-dbus.cpp +++ b/src/helpers/creds-dbus/creds-dbus.cpp @@ -15,9 +15,58 @@ */ /* * @file creds-dbus.cpp + * @author Radoslaw Bartosiak + * @author Aleksander Zdyb * @author Lukasz Wojciechowski * @version 1.0 * @brief Implementation of external libcynara-creds-dbus API */ -// Empty initial file + +#include + +#include + +#include +#include +#include + +CYNARA_API +int cynara_creds_dbus_get_client(DBusConnection *connection, const char *uniqueName, + enum cynara_client_creds method, char **client) { + if (connection == nullptr || uniqueName == nullptr || client == nullptr) + return CYNARA_API_INVALID_PARAM; + + switch (method) { + case cynara_client_creds::CLIENT_METHOD_SMACK: + return getClientSmackLabel(connection, uniqueName, client); + case cynara_client_creds::CLIENT_METHOD_PID: + return getClientPid(connection, uniqueName, client); + default: + return CYNARA_API_METHOD_NOT_SUPPORTED; + } +} + +CYNARA_API +int cynara_creds_dbus_get_user(DBusConnection *connection, const char *uniqueName, + enum cynara_user_creds method, char **user) { + if (connection == nullptr || uniqueName == nullptr || user == nullptr) + return CYNARA_API_INVALID_PARAM; + + switch (method) { + case cynara_user_creds::USER_METHOD_UID: + return getUserId(connection, uniqueName, user); + case cynara_user_creds::USER_METHOD_GID: + return getUserGid(connection, uniqueName, user); + default: + return CYNARA_API_METHOD_NOT_SUPPORTED; + } +} + +CYNARA_API +int cynara_creds_dbus_get_pid(DBusConnection *connection, const char *uniqueName, pid_t *pid) { + if (connection == nullptr || uniqueName == nullptr) + return CYNARA_API_INVALID_PARAM; + + return getPid(connection, uniqueName, pid); +} diff --git a/src/include/cynara-creds-dbus.h b/src/include/cynara-creds-dbus.h index 925a829..904e4dd 100644 --- a/src/include/cynara-creds-dbus.h +++ b/src/include/cynara-creds-dbus.h @@ -16,6 +16,7 @@ /* * @file cynara-creds-dbus.h * @author Lukasz Wojciechowski + * @author Radoslaw Bartosiak * @version 1.0 * @brief This file contains Cynara credentials helper APIs for dbus clients. */ @@ -24,11 +25,133 @@ #ifndef CYNARA_CREDS_DBUS_H #define CYNARA_CREDS_DBUS_H +#include +#include + +#include "cynara-creds-commons.h" + #ifdef __cplusplus extern "C" { #endif -/* empty initial file */ +/** + * \par Description: + * Creates a client identification string with given method. Client is a process identified by the + * unique name at the other side of the dbus connection. + * + * \par Purpose: + * Client identification string is required for cynara_check() and cynara_async_check() functions. + * + * \par Typical use case: + * The function is called before the call of one of ...check() functions. + * Returned string is used as client parameter in ...check() function. + * String is released with free() function when it is no longer needed. + * + * \par Method of function operation: + * The function generates client string by calling a method from DBus Interface + * ("org.freedesktop.DBus") which is placed on system bus ("org.freedesktop.DBus"). + * + * \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 mutex protected critical section. + * + * \par Important notes: + * Memory for returned client string is obtained with malloc(), and should be freed with free(). + * Allocated string is returned only, when function succeeds. + * + * \param[in] connection DBus connection to a bus. It manages incomming and outgoing messages + * \param[in] uniqueName DBus identifier of the client + * \param[in] method Method of client identifier creation + * \param[out] client Placeholder for allocated string containing client id + * + * \return CYNARA_API_SUCCESS on success + * CYNARA_API_INVALID_PARAM when client is NULL or uniqueName or client has wrong + * value (i.e NULL or non-existing) + * CYNARA_API_METHOD_NOT_SUPPORTED when requested method is not supported + * CYNARA_API_OUT_OF_MEMORY when there was error allocating memory + */ +int cynara_creds_dbus_get_client(DBusConnection *connection, const char *uniqueName, + enum cynara_client_creds method, char **client); + +/** + * \par Description: + * Creates a user identification string with given method. User is an executor of process + * at the other side of socket. + * + * \par Purpose: + * User identification string is required for cynara_check() and cynara_async_check() functions. + * + * \par Typical use case: + * The function is called before the call of one of ...check() functions. + * Returned string is used as user parameter in ...check() function. + * String is released with free() function when it is no longer needed. + * + * \par Method of function operation: + * The function generates user string by calling a method from DBus Interface + * ("org.freedesktop.DBus") which is placed on system bus ("org.freedesktop.DBus"). + * + * \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 mutex protected critical section. + * + * \par Important notes: + * Memory for returned user string is obtained with malloc(), and should be freed with free(). + * Allocated string is returned only, when function succeeds. + * + * \param[in] connection DBus connection to a bus. It manages incomming and outgoing messages + * \param[in] uniqueName DBus identifier of the client invoked by the user + * \param[in] method Method of client identifier creation + * \param[out] user Placeholder for allocated string containing user id + * + * \return CYNARA_API_SUCCESS on success + * CYNARA_API_INVALID_PARAM when user is NULL or connection is not valid DBus connection or + * uniqueName does not represent a process conected to the DBus + * CYNARA_API_METHOD_NOT_SUPPORTED when requested method is not supported + * CYNARA_API_OUT_OF_MEMORY when there was error allocating memory + */ +int cynara_creds_dbus_get_user(DBusConnection *connection, const char *uniqueName, + enum cynara_user_creds method, char **user); + +/** + * \par Description: + * Return PID of a proces identified by the unique name at the other side of the dbus connection. + * + * \par Purpose: + * PID may be used for client_session creation with cynara_helper_session_from_pid() function + * from libcynara-helper-session library. Client_session is needed for cynara_check() + * and cynara_async_check() functions. + * + * \par Typical use case: + * The function is called before the call of cynara_helper_session_from_pid() function. + * + * \par Method of function operation: + * The function reads PID of the peer by calling a method from DBus Interface + * ("org.freedesktop.DBus") which is placed on system bus ("org.freedesktop.DBus") + * with "GetConnectionUnixProcessID" argument. + * + * \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 mutex protected critical section. + * + * \param[in] connection DBus connection to a bus. It manages incomming and outgoing messages + * \param[in] uniqueName DBus identifier of the client invoked by the user + * \param[out] pid Placeholder for PID returned by function + * + * \return CYNARA_API_SUCCESS on success + * CYNARA_API_INVALID_PARAM when socket_fd is not valid connected socket descriptor + * CYNARA_API_UNKNOWN_ERROR when system function fails in incredible situation + * CYNARA_API_OUT_OF_MEMORY when there was error allocating memory + */ +int cynara_creds_dbus_get_pid(DBusConnection *connection, const char *uniqueName, pid_t *pid); #ifdef __cplusplus } -- 2.7.4