Add function security_manager_self_is_app() 05/315405/7
authorTomasz Swierczek <t.swierczek@samsung.com>
Mon, 25 Nov 2024 14:27:57 +0000 (15:27 +0100)
committerTomasz Swierczek <t.swierczek@samsung.com>
Fri, 13 Dec 2024 08:04:57 +0000 (09:04 +0100)
Change-Id: I03c4b947295359964578d1eb9c7e78ea2b9223ff

src/client/client-security-manager.cpp
src/include/app-runtime.h

index 6c50cfb48d518538f1415c90370e1059cf99bb95..d221c0b86c8ecfd0c94f29a1f29c98894d345cd1 100644 (file)
@@ -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)
index 82734031aa091f68c0b27c5eaaadffddf46c7404..1389db4e42f5a23a063da78216c85d6f412a39f5 100644 (file)
@@ -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
  *