Add installation types (global, local, preloaded). 12/61812/15
authorZbigniew Jasinski <z.jasinski@samsung.com>
Thu, 10 Mar 2016 14:46:55 +0000 (15:46 +0100)
committerZbigniew Jasinski <z.jasinski@samsung.com>
Tue, 15 Mar 2016 16:17:08 +0000 (17:17 +0100)
Before this commit installation type was based on UID.
With this commit it is possible to set type of installation (global, local,
preloaded) during app installation request. If type is not specified,
and installation is performed by global user, default 'SM_APP_INSTALL_GLOBAL'
type of installation is set. Otherwise installation type is set to
'SM_APP_INSTALL_LOCAL'.

New API function avaliable:

* int security_manager_app_inst_req_set_install_type(app_inst_req *p_req,
    const enum app_install_type type)

Change-Id: I745da8fc7a7393c360ed6d281a1f729d22bb89e6

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

index 033fb7f..06ccf05 100644 (file)
@@ -90,6 +90,12 @@ int security_manager_app_inst_req_new(app_inst_req **pp_req)
     }
     (*pp_req)->uid = geteuid();
 
+    uid_t globalUid = tzplatform_getuid(TZ_SYS_GLOBALAPP_USER);
+    if ((*pp_req)->uid == 0 || (*pp_req)->uid == globalUid)
+        (*pp_req)->installationType = static_cast<int>(SM_APP_INSTALL_GLOBAL);
+    else
+        (*pp_req)->installationType = static_cast<int>(SM_APP_INSTALL_LOCAL);
+
     return SECURITY_MANAGER_SUCCESS;
 }
 
@@ -177,6 +183,17 @@ int security_manager_app_inst_req_add_path(app_inst_req *p_req, const char *path
 }
 
 SECURITY_MANAGER_API
+int security_manager_app_inst_req_set_install_type(app_inst_req *p_req, const enum app_install_type type)
+{
+    if (!p_req || (type <= SM_APP_INSTALL_NONE) || (type >= SM_APP_INSTALL_END))
+        return SECURITY_MANAGER_ERROR_INPUT_PARAM;
+
+    p_req->installationType = static_cast<int>(type);
+
+    return SECURITY_MANAGER_SUCCESS;
+}
+
+SECURITY_MANAGER_API
 int security_manager_app_install(const app_inst_req *p_req)
 {
     using namespace SecurityManager;
@@ -204,7 +221,8 @@ int security_manager_app_install(const app_inst_req *p_req)
                                      p_req->appPaths,
                                      p_req->uid,
                                      p_req->tizenVersion,
-                                     p_req->authorName);
+                                     p_req->authorName,
+                                     p_req->installationType);
 
             //send buffer to server
             retval = sendToServer(SERVICE_SOCKET, send.Pop(), recv);
index a1f55e5..0e9b5c5 100644 (file)
@@ -55,6 +55,12 @@ static std::map <std::string, enum security_manager_user_type> user_type_map = {
     {"normal", SM_USER_TYPE_NORMAL}
 };
 
+static std::map <std::string, enum app_install_type> install_type_map = {
+    {"local", SM_APP_INSTALL_LOCAL},
+    {"global", SM_APP_INSTALL_GLOBAL},
+    {"preloaded", SM_APP_INSTALL_PRELOADED}
+};
+
 static po::options_description getGenericOptions()
 {
     po::options_description opts("Generic options");
@@ -95,6 +101,8 @@ static po::options_description getInstallOptions()
           "user identifier number (required)")
          ("author-id,c", po::value<std::string>(),
           "unique author's identifier (required for trusted_rw paths)")
+         ("install-type", po::value<std::string>(),
+          "type of installation (local, global, preloaded")
          ;
     return opts;
 }
@@ -236,9 +244,10 @@ static void parseInstallOptions(int argc, char *argv[],
     }
     if (vm.count("uid"))
         req.uid = vm["uid"].as<uid_t>();
-    if (vm.count("author-id")) {
+    if (vm.count("author-id"))
         req.authorName = vm["author-id"].as<std::string>();
-    }
+    if (vm.count("install-type"))
+        req.installationType = install_type_map.at(vm["install-type"].as<std::string>());
 
 }
 
index 940564b..984a5ab 100644 (file)
@@ -40,6 +40,7 @@ struct app_inst_req {
     uid_t uid;
     std::string tizenVersion;
     std::string authorName;
+    int installationType;
 };
 
 struct user_req {
index 296fd83..def5618 100644 (file)
@@ -41,7 +41,7 @@ private:
 
     static bool isSubDir(const char *parent, const char *subdir);
 
-    static bool getUserAppDir(const uid_t &uid, std::string &userAppDir);
+    static bool getUserAppDir(const uid_t &uid, const app_install_type &installType, std::string &userAppDir);
 
     static bool installRequestAuthCheck(const app_inst_req &req, uid_t uid, std::string &appPath);
 
index 2c09ec1..aa731c3 100644 (file)
@@ -207,7 +207,7 @@ bool ServiceImpl::isSubDir(const char *parent, const char *subdir)
     return (*subdir == '/' || *parent == *subdir);
 }
 
-bool ServiceImpl::getUserAppDir(const uid_t &uid, std::string &userAppDir)
+bool ServiceImpl::getUserAppDir(const uid_t &uid, const app_install_type &installType, std::string &userAppDir)
 {
     struct tzplatform_context *tz_ctx = nullptr;
 
@@ -220,8 +220,15 @@ bool ServiceImpl::getUserAppDir(const uid_t &uid, std::string &userAppDir)
     if (tzplatform_context_set_user(tz_ctxPtr.get(), uid))
         return false;
 
-    enum tzplatform_variable id =
-            (uid == getGlobalUserId()) ? TZ_SYS_RW_APP : TZ_USER_APP;
+    enum tzplatform_variable id;
+
+    if (installType == SM_APP_INSTALL_LOCAL)
+        id = TZ_USER_APP;
+    else if (installType == SM_APP_INSTALL_GLOBAL)
+        id = TZ_SYS_RW_APP;
+    else
+        id = TZ_SYS_RO_APP;
+
     const char *appDir = tzplatform_context_getenv(tz_ctxPtr.get(), id);
     if (!appDir)
         return false;
@@ -241,12 +248,14 @@ bool ServiceImpl::installRequestAuthCheck(const app_inst_req &req, uid_t uid, st
     std::string userAppDir;
     std::stringstream correctPath;
 
-    if (uid != getGlobalUserId())
-        LogDebug("Installation type: single user");
+    if (static_cast<app_install_type>(req.installationType) == SM_APP_INSTALL_LOCAL)
+        LogDebug("Installation type: local");
+    else if (static_cast<app_install_type>(req.installationType) == SM_APP_INSTALL_GLOBAL)
+        LogDebug("Installation type: global");
     else
-        LogDebug("Installation type: global installation");
+        LogDebug("Installation type: preloaded");
 
-    if (!getUserAppDir(uid, userAppDir)) {
+    if (!getUserAppDir(uid, static_cast<app_install_type>(req.installationType), userAppDir)) {
         LogError("Failed getting app dir for user uid: " << uid);
         return false;
     }
index 1d90b6a..b4fb36b 100644 (file)
@@ -112,6 +112,18 @@ int security_manager_app_inst_req_set_uid(app_inst_req *p_req,
 int security_manager_app_inst_req_set_author_id(app_inst_req *p_req, const char *author_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] Pointer handling app_inst_req structure
+ * \param[in] Installation type
+ * \return API return code or error code
+ *
+ */
+int security_manager_app_inst_req_set_install_type(app_inst_req *p_req, const enum app_install_type type);
+
+/*
  * This function is used to install application based on
  * using filled up app_inst_req data structure
  *
index 0acf328..df17a5a 100644 (file)
@@ -66,6 +66,15 @@ enum app_install_path_type {
     SECURITY_MANAGER_ENUM_END
 };
 
+enum app_install_type : int {
+    SM_APP_INSTALL_NONE = 0,
+    SM_APP_INSTALL_LOCAL,
+    SM_APP_INSTALL_GLOBAL,
+    SM_APP_INSTALL_PRELOADED,
+    SM_APP_INSTALL_END
+};
+typedef enum app_install_type app_install_type;
+
 /**
  * This enum has values equivalent to gumd user type.
  * The gum-utils help states that
index 50e5635..d5ac17a 100644 (file)
@@ -175,6 +175,7 @@ void Service::processAppInstall(MessageBuffer &buffer, MessageBuffer &send, uid_
     Deserialization::Deserialize(buffer, req.uid);
     Deserialization::Deserialize(buffer, req.tizenVersion);
     Deserialization::Deserialize(buffer, req.authorName);
+    Deserialization::Deserialize(buffer, req.installationType);
     Serialization::Serialize(send, serviceImpl.appInstall(req, uid));
 }