Add is hybrid flag to application install request 04/88304/5
authorZofia Abramowska <z.abramowska@samsung.com>
Fri, 2 Sep 2016 16:35:53 +0000 (18:35 +0200)
committerZofia Abramowska <z.abramowska@samsung.com>
Wed, 21 Sep 2016 10:55:19 +0000 (12:55 +0200)
"IsHybrid" is introduced to distinguish between different
types of packages. Hybrid package assumes, that applications
inside it can have different privileges, so they should be
labeled separately. Any other package will have all applications
labeled the same and label will be generated from package name.
This commit does not yet interpret this flag, apart from db,
From now on db will accept only applications from the same package,
which have the same setting of isHybrid flag.

Change-Id: Ic94d2147fa9684279d8b8a41ad6ee99b555cd766

db/db.sql
db/updates/update-db-to-v8.sql [new file with mode: 0644]
src/client/client-security-manager.cpp
src/common/include/privilege_db.h
src/common/include/protocols.h
src/common/privilege_db.cpp
src/common/service_impl.cpp
src/include/app-manager.h
src/server/service/service.cpp

index c85fc35ab4fecf3b838f0643bd420ed79ad5391b..f720f84644abdb02739b981f124855957738172b 100644 (file)
--- a/db/db.sql
+++ b/db/db.sql
@@ -4,13 +4,14 @@ PRAGMA auto_vacuum = NONE;
 
 BEGIN EXCLUSIVE TRANSACTION;
 
-PRAGMA user_version = 7;
+PRAGMA user_version = 8;
 
 CREATE TABLE IF NOT EXISTS pkg (
 pkg_id INTEGER PRIMARY KEY,
 name VARCHAR NOT NULL,
 author_id INTEGER,
 shared_ro INTEGER NOT NULL DEFAULT 0,
+is_hybrid INTEGER NOT NULL DEFAULT 0,
 UNIQUE (name)
 FOREIGN KEY (author_id) REFERENCES author (author_id)
 );
@@ -71,7 +72,8 @@ SELECT
     app.version as version,
     pkg.author_id,
     pkg.name as pkg_name,
-    author.name as author_name
+    author.name as author_name,
+    pkg.is_hybrid
 FROM user_app
 LEFT JOIN app USING (app_id)
 LEFT JOIN pkg USING (pkg_id)
@@ -98,10 +100,16 @@ BEGIN
                       AND NEW.author_name IS NOT NULL
                       AND author_name!=NEW.author_name);
 
+    SELECT RAISE(ABORT, 'Hybrid flag set differently for existing package')
+        WHERE EXISTS (SELECT 1 FROM user_app_pkg_view
+                      WHERE is_hybrid!=NEW.is_hybrid
+                      AND pkg_name=NEW.pkg_name);
+
     INSERT OR IGNORE INTO author(name) VALUES (NEW.author_name);
-    INSERT OR IGNORE INTO pkg(name, author_id) VALUES (
+    INSERT OR IGNORE INTO pkg(name, author_id, is_hybrid) VALUES (
         NEW.pkg_name,
-        (SELECT author_id FROM author WHERE name=NEW.author_name));
+        (SELECT author_id FROM author WHERE name=NEW.author_name),
+        NEW.is_hybrid);
 
     -- If pkg have already existed with empty author do update it
     UPDATE pkg SET author_id=(SELECT author_id FROM author WHERE name=NEW.author_name)
diff --git a/db/updates/update-db-to-v8.sql b/db/updates/update-db-to-v8.sql
new file mode 100644 (file)
index 0000000..08f2378
--- /dev/null
@@ -0,0 +1,7 @@
+BEGIN EXCLUSIVE TRANSACTION;
+
+PRAGMA user_version = 8;
+
+ALTER TABLE pkg ADD is_hybrid INTEGER NOT NULL DEFAULT 0;
+
+COMMIT TRANSACTION;
index e5cc93f7b83cd5550f4f9e0f137348eaba293f6c..6cf0c351c4d09a2965a370f555cc88d3e6322da0 100644 (file)
@@ -207,6 +207,17 @@ int security_manager_app_inst_req_set_install_type(app_inst_req *p_req, const en
     return SECURITY_MANAGER_SUCCESS;
 }
 
+SECURITY_MANAGER_API
+int security_manager_app_inst_req_set_hybrid(app_inst_req *p_req)
+{
+    if (!p_req)
+        return SECURITY_MANAGER_ERROR_INPUT_PARAM;
+
+    p_req->isHybrid = true;
+
+    return SECURITY_MANAGER_SUCCESS;
+}
+
 SECURITY_MANAGER_API
 int security_manager_app_install(const app_inst_req *p_req)
 {
@@ -237,7 +248,8 @@ int security_manager_app_install(const app_inst_req *p_req)
                                      p_req->uid,
                                      p_req->tizenVersion,
                                      p_req->authorName,
-                                     p_req->installationType);
+                                     p_req->installationType,
+                                     p_req->isHybrid);
 
             //send buffer to server
             retval = sendToServer(SERVICE_SOCKET, send.Pop(), recv);
index 1068699c50c44b45ab50d202d7f6d3c69e509ee8..8e7f80187b573aedb16046ffd15a9445e3d93356 100644 (file)
@@ -104,7 +104,8 @@ private:
 
     SecurityManager::DB::SqlConnection *mSqlConnection;
     const std::map<StmtType, const char * const > Queries = {
-        { StmtType::EAddApplication, "INSERT INTO user_app_pkg_view (app_name, pkg_name, uid, version, author_name) VALUES (?, ?, ?, ?, ?)" },
+        { StmtType::EAddApplication, "INSERT INTO user_app_pkg_view (app_name, pkg_name, uid, version, author_name, is_hybrid)"
+                                    " VALUES (?, ?, ?, ?, ?, ?)" },
         { StmtType::ERemoveApplication, "DELETE FROM user_app_pkg_view WHERE app_name=? AND uid=?" },
         { StmtType::EPkgNameExists, "SELECT count(*) FROM pkg WHERE name=?" },
         { StmtType::EAppNameExists, "SELECT count(*) FROM app WHERE name=?" },
@@ -252,6 +253,7 @@ public:
      * @param uid - user identifier for whom application is going to be installed
      * @param targetTizenVer - target tizen version for application
      * @param author - author identifier
+     * @param isHybrid - hybrid flag setting
      * @exception DB::SqlConnection::Exception::InternalError on internal error
      * @exception DB::SqlConnection::Exception::ConstraintError on constraint violation
      */
@@ -260,7 +262,8 @@ public:
             const std::string &pkgName,
             uid_t uid,
             const std::string &targetTizenVer,
-            const std::string &authorId);
+            const std::string &authorId,
+            bool isHybrid);
 
     /**
      * Remove an application from the database
index 9493cf98c9318876729d838b8c801a54cee36c93..a8eb4afbcabbf2b047766533b01214882ae45126 100644 (file)
@@ -43,6 +43,7 @@ struct app_inst_req {
     std::string tizenVersion;
     std::string authorName;
     int installationType = SM_APP_INSTALL_NONE;
+    bool isHybrid = false;
 };
 
 struct user_req {
index 895da45cc59ee645232f0252e79c3d471a962c48..75763459e4056e04c94375ccb8f3f33a7ae6873b 100644 (file)
@@ -195,7 +195,8 @@ void PrivilegeDb::AddApplication(
         const std::string &pkgName,
         uid_t uid,
         const std::string &targetTizenVer,
-        const std::string &authorName)
+        const std::string &authorName,
+        bool isHybrid)
 {
     try_catch<void>([&] {
         auto command = getStatement(StmtType::EAddApplication);
@@ -204,10 +205,11 @@ void PrivilegeDb::AddApplication(
         command->BindInteger(3, static_cast<unsigned int>(uid));
         command->BindString(4, targetTizenVer);
         authorName.empty() ? command->BindNull(5) : command->BindString(5, authorName);
+        command->BindInteger(6, isHybrid ? 1 : 0);
 
         if (command->Step()) {
             LogDebug("Unexpected SQLITE_ROW answer to query: " <<
-                    Queries.at(StmtType::EAddApplication));
+                     Queries.at(StmtType::EAddApplication));
         };
 
         LogDebug("Added appName: " << appName << ", pkgName: " << pkgName);
index fad26cc8b67a20b99f4546471aaa3cf37f9c1e1b..188cde504f2523ba001d9ef3f2a6db6e0c00ae92 100644 (file)
@@ -524,7 +524,8 @@ int ServiceImpl::appInstall(const Credentials &creds, app_inst_req &&req)
 
         PrivilegeDb::getInstance().BeginTransaction();
 
-        PrivilegeDb::getInstance().AddApplication(req.appName, req.pkgName, req.uid, req.tizenVersion, req.authorName);
+        PrivilegeDb::getInstance().AddApplication(req.appName, req.pkgName, req.uid,
+                                                  req.tizenVersion, req.authorName, req.isHybrid);
         /* Get all application ids in the package to generate rules withing the package */
         PrivilegeDb::getInstance().GetPkgApps(req.pkgName, pkgContents);
         PrivilegeDb::getInstance().GetPkgAuthorId(req.pkgName, authorId);
index d05d451b0367ecc3a1810b2c8f14c159ae584041..04b8688abf8fd998ac0999ece1bd7c2419e80840 100644 (file)
@@ -131,6 +131,19 @@ int security_manager_app_inst_req_set_author_id(app_inst_req *p_req, const char
  */
 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 flag package as hybrid. This must be done consequently for every
+ * application installed in package - if first application installed sets this flag, others also
+ * must set it, otherwise installation will fail, the same applies to non-hybrid packages -
+ * if first application doesn't set this flag, then no other application for this package can set
+ * it, otherwise its installation will fail.
+ *
+ * \param[in] p_req  Pointer handling app_inst_req structure
+ * \return API return code or error code
+ *
+ */
+int security_manager_app_inst_req_set_hybrid(app_inst_req *p_req);
+
 /**
  * This function is used to install application based on
  * using filled up app_inst_req data structure
index 394bf42a444906deefe95262b4ab16508e1338e0..5e57f7a011cf6848cb396abdf8983356c09bf150 100644 (file)
@@ -187,6 +187,7 @@ void Service::processAppInstall(MessageBuffer &buffer, MessageBuffer &send, cons
     Deserialization::Deserialize(buffer, req.tizenVersion);
     Deserialization::Deserialize(buffer, req.authorName);
     Deserialization::Deserialize(buffer, req.installationType);
+    Deserialization::Deserialize(buffer, req.isHybrid);
     Serialization::Serialize(send, serviceImpl.appInstall(creds, std::move(req)));
 }