# @file CMakeLists.txt
# @author Lukasz Wojciechowski <l.wojciechow@partner.samsung.com>
# @author Radoslaw Bartosiak <r.bartosiak@samsung.com>
+# @author Monika Zielinska <m.zielinska3@samsung.com>
#
############################# Check minimum CMake version #####################
IF (BUILD_DBUS)
SET(TARGET_LIB_CREDS_DBUS "cynara-creds-dbus")
SET(TARGET_LIB_CREDS_GDBUS "cynara-creds-gdbus")
+ IF (SYSTEMD_DEP_FOUND)
+ SET(TARGET_LIB_CREDS_SD_BUS "cynara-creds-sd-bus")
+ ENDIF (SYSTEMD_DEP_FOUND)
ENDIF (BUILD_DBUS)
ADD_SUBDIRECTORY(src)
--- /dev/null
+/*
+ * Copyright (c) 2018 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
+ */
+
+/*
+ * Get client credentials from sd_bus
+ */
+
+void cynara_log(const char *message, int cynara_status) {
+ char buf[BUFSIZ];
+
+ int ret = cynara_strerror(cynara_status, buf, BUFSIZ);
+ if (ret != CYNARA_API_SUCCESS) {
+ strncpy(buf, "cynara_strerror failed", BUFSIZ);
+ buf[BUFSIZ - 1] = '\0';
+ }
+ if (cynara_status < 0)
+ log_error("%s: %s", message, buf);
+ else
+ log_debug("%s: %s", message, buf);
+}
+
+struct Creds {
+ char *client = NULL;
+ char *user = NULL;
+ char *client_session = NULL;
+
+ ~Creds() {
+ free(client);
+ free(user);
+ free(client_session);
+ }
+};
+
+int get_credentials(sd_bus *bus, char *unique_name, Creds &creds)
+{
+ int ret = 0;
+ int pid = 0;
+
+ ret = cynara_creds_sd_bus_get_user(bus, unique_name, USER_METHOD_DEFAULT, &(creds.user));
+ if (ret != CYNARA_API_SUCCESS) {
+ cynara_log("cynara_creds_sd_bus_get_user() failed", ret);
+ return INVALID_OPERATION;
+ }
+
+ ret = cynara_creds_sd_bus_get_client(bus, unique_name, CLIENT_METHOD_DEFAULT, &(creds.client));
+ if (ret != CYNARA_API_SUCCESS) {
+ cynara_log("cynara_creds_sd_bus_get_client() failed", ret);
+ return INVALID_OPERATION;
+ }
+
+ ret = cynara_creds_sd_bus_get_pid(bus, unique_name, &pid);
+ if (ret != CYNARA_API_SUCCESS) {
+ cynara_log("cynara_creds_sd_bus_get_pid() failed", ret);
+ return INVALID_OPERATION;
+ }
+
+ creds.client_session = cynara_session_from_pid(pid);
+ return SUCCESS;
+}
%description
service, client libraries (libcynara-client, libcynara-admin),
agent library, helper libraries (libcynara-session, libcynara-creds-common, libcynara-creds-dbus,
-libcynara-creds-socket, libcynara-creds-self) and tests (cynara-tests)
+libcynara-creds-sd-bus, libcynara-creds-socket, libcynara-creds-self) and tests (cynara-tests)
%prep
%setup -q -n cynara-%{version}
--- /dev/null
+<manifest>
+ <request>
+ <domain name="_" />
+ </request>
+</manifest>
Source1000: %{name}-rpmlintrc
Source1008: libcynara-creds-dbus.manifest
Source1009: libcynara-creds-gdbus.manifest
+Source1010: libcynara-creds-sd-bus.manifest
Requires: default-ac-domains
Requires: libcynara-commons = %{version}
Requires: dbus
BuildRequires: cmake
BuildRequires: zip
BuildRequires: pkgconfig(libsmack)
+BuildRequires: pkgconfig(libsystemd)
BuildRequires: pkgconfig(dbus-1)
# alternatives: DLOG, JOURNAL, NONE, (otherwise SYSLOG is used)
%description -n libcynara-creds-gdbus
Cynara credentials helpers library for gdbus clients
+%package -n libcynara-creds-sd-bus-devel
+Summary: Development files for sd-bus helpers library
+Requires: cynara-devel = %{version}
+Requires: libcynara-creds-sd-bus = %{version}
+Requires: pkgconfig(libsystemd)
+
+%description -n libcynara-creds-sd-bus-devel
+Development files for sd-bus helpers library
+
+%package -n libcynara-creds-sd-bus
+Summary: Cynara credentials helpers library for sd-bus client
+BuildRequires: pkgconfig(libsystemd)
+Requires: libcynara-creds-commons = %{version}
+
+%description -n libcynara-creds-sd-bus
+Cynara credentials helpers library for sd-bus clients
+
%prep
%setup -q -n cynara-%{version}
cp -a %{SOURCE1008} .
cp -a %{SOURCE1009} .
+cp -a %{SOURCE1010} .
%build
export CXXFLAGS+=" -Wl,-z,relro,-z,now"
%{_libdir}/pkgconfig/cynara-creds-gdbus.pc
%{_libdir}/libcynara-creds-gdbus.so
+%files -n libcynara-creds-sd-bus-devel
+%{_includedir}/cynara/cynara-creds-sd-bus.h
+%{_libdir}/pkgconfig/cynara-creds-sd-bus.pc
+%{_libdir}/libcynara-creds-sd-bus.so
+
%files -n libcynara-creds-dbus
%manifest libcynara-creds-dbus.manifest
%license LICENSE
%license LICENSE
%{_libdir}/libcynara-creds-gdbus.so.*
+%files -n libcynara-creds-sd-bus
+%manifest libcynara-creds-sd-bus.manifest
+%license LICENSE
+%{_libdir}/libcynara-creds-sd-bus.so.*
-# Copyright (c) 2014-2016 Samsung Electronics Co., Ltd All Rights Reserved
+# Copyright (c) 2014-2018 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.
# @file CMakeLists.txt
# @author Lukasz Wojciechowski <l.wojciechow@partner.samsung.com>
# @author Radoslaw Bartosiak <r.bartosiak@samsung.com>
+# @author Monika Zielinska <m.zielinska3@samsung.com>
#
IF (BUILD_COMMONS)
IF (BUILD_DBUS)
ADD_SUBDIRECTORY(cynara-creds-dbus)
ADD_SUBDIRECTORY(cynara-creds-gdbus)
+ IF (SYSTEMD_DEP_FOUND)
+ ADD_SUBDIRECTORY(cynara-creds-sd-bus)
+ ENDIF (SYSTEMD_DEP_FOUND)
ENDIF (BUILD_DBUS)
--- /dev/null
+# Copyright (c) 2018 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 Monika Zielinska <m.zielinska3@samsung.com>
+#
+
+CONFIGURE_FILE(cynara-creds-sd-bus.pc.in cynara-creds-sd-bus.pc @ONLY)
+
+INSTALL(FILES
+ ${CMAKE_BINARY_DIR}/pkgconfig/cynara-creds-sd-bus/cynara-creds-sd-bus.pc
+ DESTINATION
+ ${LIB_DIR}/pkgconfig
+ )
--- /dev/null
+prefix=@CMAKE_INSTALL_PREFIX@
+exec_prefix=${prefix}
+libdir=@LIB_DIR@
+includedir=${prefix}/include
+
+Name: cynara-creds-sd-bus
+Description: cynara-creds package for sd-bus clients
+Version: @CYNARA_VERSION@
+Requires: systemd
+Libs: -L${libdir} -lcynara-creds-sd-bus -lcynara-creds-commons -lcynara-commons
+Cflags: -I${includedir}/cynara
#
# @file CMakeLists.txt
# @author Lukasz Wojciechowski <l.wojciechow@partner.samsung.com>
+# @author Monika Zielinska <m.zielinska3@samsung.com>
#
IF (BUILD_DBUS)
ADD_SUBDIRECTORY(helpers/creds-dbus)
ADD_SUBDIRECTORY(helpers/creds-gdbus)
+ IF (SYSTEMD_DEP_FOUND)
+ ADD_SUBDIRECTORY(helpers/creds-sd-bus)
+ ENDIF (SYSTEMD_DEP_FOUND)
ENDIF (BUILD_DBUS)
--- /dev/null
+# Copyright (c) 2018 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 Monika Zielinska <m.zielinska3@samsung.com>
+#
+
+SET(LIB_CREDS_SD_BUS_VERSION_MAJOR 0)
+SET(LIB_CREDS_SD_BUS_VERSION ${LIB_CREDS_SD_BUS_VERSION_MAJOR}.14.20)
+
+SET(LIB_CREDS_SD_BUS_PATH ${CYNARA_PATH}/helpers/creds-sd-bus)
+
+SET(LIB_CREDS_SD_BUS_SOURCES
+ ${LIB_CREDS_SD_BUS_PATH}/creds-sd-bus.cpp
+ ${LIB_CREDS_SD_BUS_PATH}/creds-sd-bus-inner.cpp
+ )
+
+INCLUDE_DIRECTORIES(
+ SYSTEM
+ ${SYSTEMD_DEP_INCLUDE_DIRS}
+ )
+INCLUDE_DIRECTORIES(
+ ${CYNARA_PATH}/include
+ ${LIB_CREDS_SD_BUS_PATH}
+ )
+
+ADD_LIBRARY(${TARGET_LIB_CREDS_SD_BUS} SHARED ${LIB_CREDS_SD_BUS_SOURCES})
+
+SET_TARGET_PROPERTIES(
+ ${TARGET_LIB_CREDS_SD_BUS}
+ PROPERTIES
+ SOVERSION ${LIB_CREDS_SD_BUS_VERSION_MAJOR}
+ VERSION ${LIB_CREDS_SD_BUS_VERSION}
+ )
+
+TARGET_LINK_LIBRARIES(${TARGET_LIB_CREDS_SD_BUS}
+ ${SYSTEMD_DEP_LIBRARIES}
+ ${TARGET_LIB_CREDS_COMMONS}
+ )
+
+INSTALL(TARGETS ${TARGET_LIB_CREDS_SD_BUS} DESTINATION ${LIB_DIR})
--- /dev/null
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+/**
+ * @file src/helpers/creds-sd-bus/creds-sd-bus-inner.cpp
+ * @author Monika Zielinska <m.zielinska3@samsung.com>
+ * @version 1.0
+ * @brief Implementation of internal libcynara-creds-sd-bus functions
+ */
+
+#include <cerrno>
+#include <cstring>
+
+#include <systemd/sd-bus.h>
+
+#include <cynara-error.h>
+#include <exceptions/TryCatch.h>
+
+#include <creds-sd-bus-inner.h>
+
+int copyStr(char **destStr, const std::string &str) {
+ if (!destStr) {
+ return CYNARA_API_INVALID_PARAM;
+ }
+ char *destTmp = strdup(str.c_str());
+ if (!destTmp) {
+ LOGE("strdup failed");
+ return CYNARA_API_OUT_OF_MEMORY;
+ }
+ *destStr = destTmp;
+ return CYNARA_API_SUCCESS;
+}
+
+int getPid(sd_bus *bus, const char *name, pid_t *pid) {
+ return Cynara::tryCatch([&bus, &name, &pid]() {
+ sd_bus_creds *creds;
+ int ret = sd_bus_get_name_creds(bus, name, SD_BUS_CREDS_PID, &creds);
+ if (ret < 0) {
+ LOGE("Couldn't get name creds: %s", std::strerror(-ret));
+ return CYNARA_API_UNKNOWN_ERROR;
+ }
+
+ ret = sd_bus_creds_get_pid(creds, pid);
+ sd_bus_creds_unref(creds);
+
+ if (ret < 0) {
+ LOGE("Couldn't get pid from creds: %s", std::strerror(-ret));
+ return CYNARA_API_UNKNOWN_ERROR;
+ }
+ return CYNARA_API_SUCCESS;
+ });
+}
+
+int getClientPid(sd_bus *bus, const char *name, char **client) {
+ return Cynara::tryCatch([&bus, &name, &client]() {
+ pid_t pid;
+ int ret = getPid(bus, name, &pid);
+ if (ret != CYNARA_API_SUCCESS)
+ return ret;
+ return copyStr(client, std::to_string(pid));
+ });
+}
+
+int getClientSmackLabel(sd_bus *bus, const char *name, char **client) {
+ return Cynara::tryCatch([&bus, &name, &client]() {
+ sd_bus_creds *creds;
+ const char *label;
+
+ /* There's no API specially for Smack label, but SELINUX_CONTEXT maps to a standard Linux Security Label */
+ int ret = sd_bus_get_name_creds(bus, name, SD_BUS_CREDS_AUGMENT | SD_BUS_CREDS_SELINUX_CONTEXT, &creds);
+ if (ret < 0) {
+ LOGE("Couldn't get name creds: %s", std::strerror(-ret));
+ return CYNARA_API_UNKNOWN_ERROR;
+ }
+
+ ret = sd_bus_creds_get_selinux_context(creds, &label);
+ if (ret < 0) {
+ sd_bus_creds_unref(creds);
+ LOGE("Couldn't get smack label from creds: %s", std::strerror(-ret));
+ return CYNARA_API_UNKNOWN_ERROR;
+ }
+
+ ret = copyStr(client, label);
+ sd_bus_creds_unref(creds);
+ return ret;
+ });
+}
+
+int getUserId(sd_bus *bus, const char *name, char **user) {
+ return Cynara::tryCatch([&bus, &name, &user]() {
+ sd_bus_creds *creds;
+ uid_t uid;
+ int ret = sd_bus_get_name_creds(bus, name, SD_BUS_CREDS_AUGMENT | SD_BUS_CREDS_UID, &creds);
+ if (ret < 0) {
+ LOGE("Couldn't get name creds: %s", std::strerror(-ret));
+ return CYNARA_API_UNKNOWN_ERROR;
+ }
+
+ ret = sd_bus_creds_get_uid(creds, &uid);
+ sd_bus_creds_unref(creds);
+ if (ret < 0) {
+ LOGE("Couldn't get uid from creds: %s", std::strerror(-ret));
+ return CYNARA_API_UNKNOWN_ERROR;
+ }
+ return copyStr(user, std::to_string(uid));
+ });
+}
+
+int getUserGid(sd_bus *bus, const char *name, char **user) {
+ return Cynara::tryCatch([&bus, &name, &user]() {
+ sd_bus_creds *creds;
+ gid_t gid;
+ int ret = sd_bus_get_name_creds(bus, name, SD_BUS_CREDS_AUGMENT | SD_BUS_CREDS_GID, &creds);
+ if (ret < 0) {
+ LOGE("Couldn't get name creds: %s", std::strerror(-ret));
+ return CYNARA_API_UNKNOWN_ERROR;
+ }
+
+ ret = sd_bus_creds_get_gid(creds, &gid);
+ sd_bus_creds_unref(creds);
+ if (ret < 0) {
+ LOGE("Couldn't get gid from creds: %s", std::strerror(-ret));
+ return CYNARA_API_UNKNOWN_ERROR;
+ }
+ return copyStr(user, std::to_string(gid));
+ });
+}
--- /dev/null
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+/**
+ * @file src/helpers/creds-sd-bus/creds-sd-bus-inner.h
+ * @author Monika Zielinska <m.zielinska3@samsung.com>
+ * @version 1.0
+ * @brief Definition of internal libcynara-creds-sd-bus functions
+ */
+
+#ifndef SRC_HELPERS_CREDSSDBUS_CREDSSDBUSINNER_H_
+#define SRC_HELPERS_CREDSSDBUS_CREDSSDBUSINNER_H_
+
+#include <systemd/sd-bus.h>
+
+int getClientSmackLabel(sd_bus *bus, const char *name, char **client);
+int getClientPid(sd_bus *bus, const char *name, char **client);
+int getUserId(sd_bus *bus, const char *name, char **user);
+int getUserGid(sd_bus *bus, const char *name, char **user);
+
+int getPid(sd_bus *bus, const char *name, pid_t *pid);
+
+#endif /* SRC_HELPERS_CREDSSDBUS_CREDSSDBUSINNER_H_ */
--- /dev/null
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+/**
+ * @file src/helpers/creds-sd-bus/creds-sd-bus.cpp
+ * @author Monika Zielinska <m.zielinska3@samsung.com>
+ * @version 1.0
+ * @brief Implementation of external libcynara-creds-sd-bus API
+ */
+
+#include <attributes/attributes.h>
+#include <cynara-creds-commons.h>
+#include <cynara-creds-sd-bus.h>
+#include <cynara-error.h>
+#include <log/log.h>
+
+#include <creds-sd-bus-inner.h>
+
+CYNARA_API
+int cynara_creds_sd_bus_get_client(sd_bus *bus, const char *name,
+ enum cynara_client_creds method, char **client) {
+ if (bus == nullptr) {
+ LOGE("Invalid bus parameter");
+ return CYNARA_API_INVALID_PARAM;
+ }
+
+ if (name == nullptr) {
+ LOGE("Invalid name parameter");
+ return CYNARA_API_INVALID_PARAM;
+ }
+
+ if (client == nullptr) {
+ LOGE("Invalid client parameter");
+ return CYNARA_API_INVALID_PARAM;
+ }
+
+ if (method == cynara_client_creds::CLIENT_METHOD_DEFAULT) {
+ int ret = cynara_creds_get_default_client_method(&method);
+ if (ret != CYNARA_API_SUCCESS)
+ return ret;
+ }
+
+ switch (method) {
+ case cynara_client_creds::CLIENT_METHOD_SMACK:
+ return getClientSmackLabel(bus, name, client);
+ case cynara_client_creds::CLIENT_METHOD_PID:
+ return getClientPid(bus, name, client);
+ default:
+ return CYNARA_API_METHOD_NOT_SUPPORTED;
+ }
+}
+
+CYNARA_API
+int cynara_creds_sd_bus_get_user(sd_bus *bus, const char *name,
+ enum cynara_user_creds method, char **user) {
+ if (bus == nullptr) {
+ LOGE("Invalid bus parameter");
+ return CYNARA_API_INVALID_PARAM;
+ }
+
+ if (name == nullptr) {
+ LOGE("Invalid name parameter");
+ return CYNARA_API_INVALID_PARAM;
+ }
+
+ if (user == nullptr) {
+ LOGE("Invalid user parameter");
+ return CYNARA_API_INVALID_PARAM;
+ }
+
+ if (method == cynara_user_creds::USER_METHOD_DEFAULT) {
+ int ret = cynara_creds_get_default_user_method(&method);
+ if (ret != CYNARA_API_SUCCESS)
+ return ret;
+ }
+
+ switch (method) {
+ case cynara_user_creds::USER_METHOD_UID:
+ return getUserId(bus, name, user);
+ case cynara_user_creds::USER_METHOD_GID:
+ return getUserGid(bus, name, user);
+ default:
+ return CYNARA_API_METHOD_NOT_SUPPORTED;
+ }
+}
+
+CYNARA_API
+int cynara_creds_sd_bus_get_pid(sd_bus *bus, const char *name, pid_t *pid) {
+ if (bus == nullptr) {
+ LOGE("Invalid bus parameter");
+ return CYNARA_API_INVALID_PARAM;
+ }
+
+ if (name == nullptr) {
+ LOGE("Invalid name parameter");
+ return CYNARA_API_INVALID_PARAM;
+ }
+
+ if (pid == nullptr) {
+ LOGE("Invalid pid parameter");
+ return CYNARA_API_INVALID_PARAM;
+ }
+ return getPid(bus, name, pid);
+}
-# Copyright (c) 2014-2016 Samsung Electronics Co., Ltd All Rights Reserved
+# Copyright (c) 2014-2018 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.
#
# @file CMakeLists.txt
# @author Lukasz Wojciechowski <l.wojciechow@partner.samsung.com>
+# @author Monika Zielinska <m.zielinska3@samsung.com>
#
IF (BUILD_COMMONS)
INSTALL(FILES
${CYNARA_PATH}/include/cynara-creds-dbus.h
${CYNARA_PATH}/include/cynara-creds-gdbus.h
+ ${CYNARA_PATH}/include/cynara-creds-sd-bus.h
DESTINATION ${INCLUDE_DIR}/cynara
)
ENDIF (BUILD_DBUS)
--- /dev/null
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+/**
+ * @file src/include/cynara-creds-sd-bus.h
+ * @author Monika Zielinska <m.zielinska3@samsung.com>
+ * @version 1.0
+ * @brief This file contains Cynara credentials helper APIs for sdbus clients.
+ * @example cynara-creds-sd-bus.example
+ */
+
+#ifndef CYNARA_CREDS_SD_BUS_H
+#define CYNARA_CREDS_SD_BUS_H
+
+#include <systemd/sd-bus.h>
+
+#include <cynara-creds-commons.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \par Description:
+ * Creates a client identification string with given method. Client is a process connected to
+ * the bus and identified by the unique name.
+ *
+ * \par Purpose:
+ * Client identification string is required for cynara_check() and cynara_async_create_request()
+ * functions.
+ *
+ * \par Typical use case:
+ * The function is called before the call of cynara_check() or cynara_async_create_request()
+ * function. Returned string is used as client parameter in cynara_check() or
+ * cynara_async_create_request() 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 sd_bus_get_name_creds function or by reading
+ * /proc/(pid)/attr/current file depending on chosen method.
+ *
+ * \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.
+ * If method is CLIENT_METHOD_DEFAULT then it will be chosen based on Cynara configuration file.
+ *
+ * \param[in] bus Bus connection that manages incoming and outgoing messages
+ * \param[in] name Bus 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
+ * \return CYNARA_API_INVALID_PARAM when client is NULL or uniqueName or client has wrong
+ * value (i.e NULL or non-existing)
+ * \return CYNARA_API_METHOD_NOT_SUPPORTED when requested method is not supported
+ * \return CYNARA_API_CONFIGURATION_ERROR if the configuration file can not be opened or
+ * there are errors in configuration file
+ * \return CYNARA_API_OUT_OF_MEMORY when there is error allocating memory
+ * \return CYNARA_API_UNKNOWN_ERROR if there is other error
+ */
+int cynara_creds_sd_bus_get_client(sd_bus *bus, const char *name,
+ enum cynara_client_creds method, char **client);
+
+/**
+ * \par Description:
+ * Creates a user identification string with given method. User is an executor of a process
+ * connected to the bus and identified by the unique name.
+ *
+ * \par Purpose:
+ * User identification string is required for cynara_check() and cynara_async_create_request()
+ * functions.
+ *
+ * \par Typical use case:
+ * The function is called before the call of cynara_check() or cynara_async_create_request()
+ * function. Returned string is used as user parameter in cynara_check() or
+ * cynara_async_create_request() 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 sd_bus_get_name_creds function.
+ *
+ * \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.
+ * If method is USER_METHOD_DEFAULT then it will be chosen based on Cynara configuration file.
+ *
+ * \param[in] bus Bus connection that manages incoming and outgoing messages
+ * \param[in] name Bus 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
+ * \return CYNARA_API_INVALID_PARAM when user is NULL or uniqueName or client has wrong
+ * value (i.e NULL or non-existing)
+ * \return CYNARA_API_METHOD_NOT_SUPPORTED when requested method is not supported
+ * \return CYNARA_API_CONFIGURATION_ERROR if the configuration file can not be opened or
+ * there are errors in configuration file
+ * \return CYNARA_API_OUT_OF_MEMORY when there is error allocating memory
+ * \return CYNARA_API_UNKNOWN_ERROR if there is other error
+ */
+int cynara_creds_sd_bus_get_user(sd_bus *bus, const char *name,
+ enum cynara_user_creds method, char **user);
+
+/**
+ * \par Description:
+ * Return PID of a process connected to the bus and identified by the unique name.
+ *
+ * \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_create_request() 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 client by calling sd_bus_creds_get_pid methods.
+ *
+ * \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] bus Bus connection that manages incoming and outgoing messages
+ * \param[in] name Bus identifier of the client invoked by the user
+ * \param[out] pid Placeholder for PID returned by function
+ *
+ * \return CYNARA_API_SUCCESS on success
+ * \return CYNARA_API_UNKNOWN_ERROR when function fails because of unknown error
+ */
+int cynara_creds_sd_bus_get_pid(sd_bus *bus, const char *name, pid_t *pid);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* CYNARA_CREDS_SD_BUS_H */