Add path registration API stub 44/67844/8
authorKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Wed, 27 Apr 2016 09:19:43 +0000 (11:19 +0200)
committerGerrit Code Review <gerrit@review.vlan103.tizen.org>
Fri, 13 May 2016 16:03:05 +0000 (09:03 -0700)
[Problem] Path registration is package specific and requires a separate
processing.
[Solution] Create API for package path registration.

[Verification] Successfull compilation

Change-Id: Ie31d756b7dc7ca9bca82305b03dd8000ba6b9bc5

src/client/client-security-manager.cpp
src/cmd/security-manager-cmd.cpp
src/common/include/protocols.h
src/common/service_impl.cpp
src/include/app-manager.h
src/include/security-manager-types.h
src/server/service/service.cpp

index dd55443..9958c49 100755 (executable)
@@ -173,7 +173,7 @@ int security_manager_app_inst_req_add_path(app_inst_req *p_req, const char *path
     if (!p_req || !path || (path_type < 0) || (path_type >= SECURITY_MANAGER_ENUM_END))
         return SECURITY_MANAGER_ERROR_INPUT_PARAM;
 
-    p_req->appPaths.push_back(std::make_pair(path, path_type));
+    p_req->pkgPaths.push_back(std::make_pair(path, path_type));
 
     return SECURITY_MANAGER_SUCCESS;
 }
@@ -215,7 +215,7 @@ int security_manager_app_install(const app_inst_req *p_req)
                                      p_req->appName,
                                      p_req->pkgName,
                                      p_req->privileges,
-                                     p_req->appPaths,
+                                     p_req->pkgPaths,
                                      p_req->uid,
                                      p_req->tizenVersion,
                                      p_req->authorName,
index 0e9b5c5..762587b 100644 (file)
@@ -192,7 +192,7 @@ static bool loadPaths(const std::vector<std::string> &paths,
         LogDebug("Wrong paths size: " << paths.size());
         return false;
     }
-    req.appPaths.clear();
+    req.pkgPaths.clear();
     for (std::vector<std::string>::size_type i = 1; i < paths.size(); i += 2) {
         app_install_path_type pathType;
         LogDebug("path: " << paths[i - 1]);
@@ -201,13 +201,13 @@ static bool loadPaths(const std::vector<std::string> &paths,
         } catch (const std::out_of_range &e) {
             std::cout << "Invalid path type found." << std::endl;
             LogError("Invalid path type found.");
-            req.appPaths.clear();
+            req.pkgPaths.clear();
             return false;
         }
         LogDebug("path type: " << pathType << " (" << paths[i] << ")");
-        req.appPaths.push_back(std::make_pair(paths[i - 1], pathType));
+        req.pkgPaths.push_back(std::make_pair(paths[i - 1], pathType));
     }
-    return (!req.appPaths.empty());
+    return (!req.pkgPaths.empty());
 }
 
 static void parseInstallOptions(int argc, char *argv[],
index 2283205..3926606 100644 (file)
 #include <dpl/serialization.h>
 #include <security-manager-types.h>
 
+typedef std::vector<std::pair<std::string, int>> pkg_paths;
+
 struct app_inst_req {
     std::string appName;
     std::string pkgName;
     std::vector<std::string> privileges;
-    std::vector<std::pair<std::string, int>> appPaths;
+    pkg_paths pkgPaths;
     uid_t uid;
     std::string tizenVersion;
     std::string authorName;
@@ -54,6 +56,13 @@ struct private_sharing_req {
     std::vector<std::string> paths;
 };
 
+struct path_req {
+    std::string pkgName;
+    uid_t uid;
+    pkg_paths pkgPaths;
+    int installationType = SM_APP_INSTALL_NONE;
+};
+
 namespace SecurityManager {
 
 extern char const * const SERVICE_SOCKET;
index 9e4cb22..a961d24 100755 (executable)
@@ -298,7 +298,7 @@ bool ServiceImpl::installRequestPathsCheck(const app_inst_req &req, std::string
     correctPath.append("/").append(req.pkgName);
     LogDebug("correctPath: " << correctPath);
 
-    for (const auto &path : req.appPaths) {
+    for (const auto &path : req.pkgPaths) {
         std::unique_ptr<char, std::function<void(void*)>> real_path(
             realpath(path.first.c_str(), NULL), free);
         if (!real_path.get()) {
@@ -402,11 +402,11 @@ int ServiceImpl::appInstall(const Credentials &creds, app_inst_req &&req)
     }
 
     try {
-        if (!req.appPaths.empty())
+        if (!req.pkgPaths.empty())
             SmackLabels::setupAppBasePath(req.pkgName, appPath);
 
         // register paths
-        for (const auto &appPath : req.appPaths) {
+        for (const auto &appPath : req.pkgPaths) {
             const std::string &path = appPath.first;
             app_install_path_type pathType = static_cast<app_install_path_type>(appPath.second);
             SmackLabels::setupPath(req.pkgName, path, pathType, authorId);
index c297d75..02207b2 100644 (file)
@@ -153,6 +153,82 @@ int security_manager_app_install(const app_inst_req *p_req);
  */
 int security_manager_app_uninstall(const app_inst_req *p_req);
 
+/*
+ * This function is responsible for initialize path_req data structure. It uses
+ * dynamic allocation inside and user responsibility is to call
+ * security_manager_path_req_free() for freeing allocated resources.
+ *
+ * \param[in] pp_req    Address of pointer for handle path_req structure
+ * \return API return code or error code
+ */
+int security_manager_path_req_new(path_req **pp_req);
+
+/*
+ * This function is used to free resources allocated by calling
+ * security_manager_path_req_new().
+ *  \param[in] p_req    Pointer handling allocated path_req structure
+ */
+void security_manager_path_req_free(path_req *p_req);
+
+/*
+ * This function is used to set up package identifier in path_req structure.
+ *
+ * \param[in] p_req     Pointer handling path_req structure
+ * \param[in] pkg_id    Package identifier
+ * \return API return code or error code
+ */
+int security_manager_path_req_set_pkg_id(path_req *p_req, const char *pkg_id);
+
+/*
+ * This function is used to set up installation type (global, local, preloaded).
+ * If type is not set and if installation is performed by global user, type is set to
+ * 'SM_APP_INSTALL_GLOBAL'. Otherwise installation type is set to 'SM_APP_INSTALL_LOCAL'.
+ *
+ * \param[in] p_req     Pointer handling path_req structure
+ * \param[in] type      Installation type
+ * \return API return code or error code
+ */
+int security_manager_path_req_set_install_type(path_req *p_req, const enum app_install_type type);
+
+/*
+ * This function is used to add a package path to path_req structure. It can be
+ * called multiple times.
+ *
+ * \param[in] p_req     Pointer handling path_req structure
+ * \param[in] path      Package path
+ * \param[in] path_type Package path type
+ * \return API return code or error code
+ */
+int security_manager_path_req_add_path(path_req *p_req, const char *path, const int path_type);
+
+/*
+ * This function is used to set up user identifier in path_req structure.
+ * This field simplifies support for online and offline modes.
+ *
+ * \param[in] p_req     Pointer handling path_req structure
+ * \param[in] uid       User identifier (UID)
+ * \return API return code or error code
+ */
+int security_manager_path_req_set_uid(path_req *p_req, const uid_t uid);
+
+/*
+ * This function is used to register a set of paths for given package using
+ * filled up path_req data structure.
+ *
+ * Required privileges:
+ * - http://tizen.org/privilege/notexist (if uid is not set or set to current user's uid)
+ * - http://tizen.org/privilege/notexist (if uid is set to some other user's uid)
+ *
+ * \param[in] p_req     Pointer handling path_req structure
+ *
+ * \return API return code or error code: it would be
+ * - SECURITY_MANAGER_SUCCESS on success,
+ * - SECURITY_MANAGER_ERROR_AUTHENTICATION_FAILED when user does not
+ * have rights to install requested directories,
+ * - SECURITY_MANAGER_ERROR_UNKNOWN on other errors.
+ */
+int security_manager_paths_register(const path_req *p_req);
+
 #ifdef __cplusplus
 }
 #endif
index 01820b4..8f1c1db 100644 (file)
@@ -115,6 +115,11 @@ typedef struct policy_entry policy_entry;
 struct private_sharing_req;
 typedef struct private_sharing_req private_sharing_req;
 
+/*! brief data structure responsible for handling informations required to register
+ * a set of paths for given package. */
+struct path_req;
+typedef struct path_req path_req;
+
 /*! \brief wildcard to be used in requests to match all possible values of given field.
  *         Use it, for example when it is desired to list or apply policy change for all
  *         users or all apps for selected user.
index a0607a0..a102801 100644 (file)
@@ -163,7 +163,7 @@ void Service::processAppInstall(MessageBuffer &buffer, MessageBuffer &send, cons
     Deserialization::Deserialize(buffer, req.appName);
     Deserialization::Deserialize(buffer, req.pkgName);
     Deserialization::Deserialize(buffer, req.privileges);
-    Deserialization::Deserialize(buffer, req.appPaths);
+    Deserialization::Deserialize(buffer, req.pkgPaths);
     Deserialization::Deserialize(buffer, req.uid);
     Deserialization::Deserialize(buffer, req.tizenVersion);
     Deserialization::Deserialize(buffer, req.authorName);