From 39b404f6b0f67ba948b6ca132f3961730cb6bfca Mon Sep 17 00:00:00 2001 From: Zofia Abramowska Date: Fri, 16 Sep 2016 11:57:35 +0200 Subject: [PATCH] Add API for identifying application from Cynara client Change-Id: I1f906cb2200fc38e99f5225b951b596ff2d5c507 --- src/client/client-security-manager.cpp | 15 +++++++++++++++ src/include/app-runtime.h | 18 ++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/src/client/client-security-manager.cpp b/src/client/client-security-manager.cpp index e8e854a..d903574 100644 --- a/src/client/client-security-manager.cpp +++ b/src/client/client-security-manager.cpp @@ -1341,6 +1341,21 @@ int security_manager_identify_app_from_pid(pid_t pid, char **pkg_name, char **ap } SECURITY_MANAGER_API +int security_manager_identify_app_from_cynara_client(const char *client, char **pkg_name, + char **app_name) +{ + return try_catch([&] { + LogDebug(__PRETTY_FUNCTION__ << " called"); + + if (pkg_name == NULL && app_name == NULL) { + LogError("Both pkg_name and app_name are NULL"); + return SECURITY_MANAGER_ERROR_INPUT_PARAM; + } + return get_app_and_pkg_id_from_smack_label(client, pkg_name, app_name); + }); +} + +SECURITY_MANAGER_API int security_manager_app_has_privilege(const char *app_name, const char *privilege, uid_t uid, int *result) { diff --git a/src/include/app-runtime.h b/src/include/app-runtime.h index 3303523..1d7028c 100644 --- a/src/include/app-runtime.h +++ b/src/include/app-runtime.h @@ -162,6 +162,24 @@ int security_manager_identify_app_from_socket(int sockfd, char **pkg_id, char ** int security_manager_identify_app_from_pid(pid_t pid, char **pkg_id, char **app_id); /** + * Get package and application id of an application with given process Cynara client identifier + * + * On successful call pkg_id and app_id should be freed when caller is done with them. + * Both pkg_id and app_id are allocated with malloc() so they should be freed with free() function. + * Either app_id or pkg_id may be NULL. NULL-ed argument will be ignored. + * If both app_id and pkg_id are NULL then SECURITY_MANAGER_ERROR_INPUT_PARAM will be returned. + * When process identifier is incorrect or not related to any package, this function will + * return SECURITY_MANAGER_ERROR_NO_SUCH_OBJECT. + * + * + * \param[in] client Application Cynara client identifier + * \param[out] pkg_id Package id of the application + * \param[out] app_id Application id of the application + * \return API return code or error code + */ +int security_manager_identify_app_from_cynara_client(const char *client, char **pkg_id, + char **app_id); +/** * Check whether an application would have access to a privilege * * This enables queries for application's privileges when there is no application -- 2.7.4