From: Tomasz Swierczek Date: Mon, 25 Nov 2024 14:27:57 +0000 (+0100) Subject: Add function security_manager_self_is_app() X-Git-Tag: accepted/tizen/unified/20241216.010927~7 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=27857050a19c56abecc6f6d30a1b95d631e7da08;p=platform%2Fcore%2Fsecurity%2Fsecurity-manager.git Add function security_manager_self_is_app() Change-Id: I03c4b947295359964578d1eb9c7e78ea2b9223ff --- diff --git a/src/client/client-security-manager.cpp b/src/client/client-security-manager.cpp index 6c50cfb4..d221c0b8 100644 --- a/src/client/client-security-manager.cpp +++ b/src/client/client-security-manager.cpp @@ -1794,6 +1794,26 @@ int security_manager_identify_app_from_pid(pid_t pid, char **pkg_name, char **ap }); } +SECURITY_MANAGER_API +int security_manager_self_is_app(bool *app) +{ + if (!app) + return SECURITY_MANAGER_ERROR_INPUT_PARAM; + char * pkgId = NULL; + int ret = security_manager_identify_app_from_pid(getpid(), &pkgId, NULL); + + *app = SECURITY_MANAGER_ERROR_NO_SUCH_OBJECT != ret && pkgId; + + if (pkgId) + free(pkgId); + + if (ret != SECURITY_MANAGER_SUCCESS && ret != SECURITY_MANAGER_ERROR_NO_SUCH_OBJECT) + // its neither an app nor not-app, something went wrong in the process + return SECURITY_MANAGER_ERROR_UNKNOWN; + + return SECURITY_MANAGER_SUCCESS; +} + SECURITY_MANAGER_API int security_manager_identify_app_from_cynara_client(const char *client, char **pkg_name, char **app_name) diff --git a/src/include/app-runtime.h b/src/include/app-runtime.h index 82734031..1389db4e 100644 --- a/src/include/app-runtime.h +++ b/src/include/app-runtime.h @@ -206,6 +206,15 @@ 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); +/** + * Return true or false depending the caller being an app or not. + * Function checks attributes of process in /proc and maps it to an app or other process. + * + * \param[out] app returned boolean value; must not be null + * \return SECURITY_MANAGER_SUCCESS or error code + */ +int security_manager_self_is_app(bool *app); + /** * Get package and application id of an application with given process Cynara client identifier *