Fix for migrate legacy image 44/153644/3
authorSangyoon Jang <jeremy.jang@samsung.com>
Fri, 29 Sep 2017 04:27:08 +0000 (13:27 +0900)
committerSangyoon Jang <jeremy.jang@samsung.com>
Mon, 20 Nov 2017 08:45:14 +0000 (08:45 +0000)
When migrate wgt legacy image, security context should be installed
first for path labeling.

Change-Id: I684c206b45c447c45ac398c44cc06da94e60de7a
Signed-off-by: Sangyoon Jang <jeremy.jang@samsung.com>
src/common/pkgmgr_query.cc
src/common/pkgmgr_query.h
src/common/security_registration.h
src/common/step/configuration/step_configure.cc
src/common/step/filesystem/step_migrate_legacy_external_image.cc

index d06ed707f7d83936d7208d98050456cccf22345f..42ce2ce58ce26c8ab21b7559ac7e17a97f31a34c 100644 (file)
@@ -162,6 +162,22 @@ std::string QueryStorageForPkgId(const std::string& pkg_id, uid_t uid) {
   return installed_location;
 }
 
+std::string QueryMainappIdForPkgId(const std::string& pkg_id, uid_t uid) {
+  pkgmgrinfo_pkginfo_h package_info;
+  if (pkgmgrinfo_pkginfo_get_usr_all_pkginfo(pkg_id.c_str(), uid, &package_info)
+      != PMINFO_R_OK)
+    return {};
+
+  char* mainapp_id = nullptr;
+  bool ret = pkgmgrinfo_pkginfo_get_mainappid(package_info,
+      &mainapp_id) == PMINFO_R_OK;
+  std::string mainapp_id_value;
+  if (mainapp_id)
+    mainapp_id_value = mainapp_id;
+  pkgmgrinfo_pkginfo_destroy_pkginfo(package_info);
+  return mainapp_id_value;
+}
+
 bool QueryIsPackageInstalled(const std::string& pkg_id,
                              RequestMode request_mode, uid_t uid) {
   pkgmgrinfo_pkginfo_h handle;
index c3d8cccd25caf802907086db9a0b9f4bfc147fb5..b7c9b1963b720515196416f2f80285f59d45990f 100644 (file)
@@ -83,6 +83,17 @@ bool QueryPrivilegesForPkgId(const std::string& pkg_id, uid_t uid,
  */
 std::string QueryStorageForPkgId(const std::string& pkg_id, uid_t uid);
 
+/**
+ * \brief Adapter interface for external PkgMgr module used for getting
+ *        storage for given package
+ *
+ * \param pkg_id id of package
+ * \param uid user id
+ *
+ * \return mainapp_id of empty if not installed
+ */
+std::string QueryMainappIdForPkgId(const std::string& pkg_id, uid_t uid);
+
 /**
  * \brief Adapter interface for external PkgMgr module used for checking
  *        if given package is installed/registered
index 996a03ed67132219afbc82ac3f820b3040876382..5d73b5250474f677323e1f6eef15faed5c38b280 100644 (file)
 
 namespace common_installer {
 
+bool RegisterSecurityContext(const std::string& app_id,
+    const std::string& pkg_id, const std::string& author_id,
+    const std::string& api_version, const boost::filesystem::path& path,
+    uid_t uid, const std::vector<std::string>& privileges,
+    bool cross_app_rules, std::string* error_message);
+
 /**
  * Adapter interface for external Security module.
  *
index 122b169539764e7401f959562bfdf54c7461095a..702dc664881a5156edca722cf1b85198400e2794 100644 (file)
@@ -141,6 +141,7 @@ Step::Status StepConfigure::process() {
       bf::path package_directory =
           context_->root_application_path.get() / context_->pkgid.get();
       context_->pkg_path.set(package_directory);
+      context_->unpacked_dir_path.set(package_directory);
       break;
     }
     default:
index 9066ff72ab0472fb0359c444556e2ba0e4ca3eae..15e97ef8fbacd9a12b04ebf8b0946ff773d3e807 100644 (file)
@@ -76,6 +76,20 @@ Step::Status StepMigrateLegacyExtImage::process() {
   }
 
   std::string error_message;
+  if (context_->pkg_type.get() == "wgt") {
+    std::string mainapp_id = QueryMainappIdForPkgId(pkgid, uid);
+    if (mainapp_id.empty())
+      mainapp_id = pkgid;
+    // This is for 2.4 -> 3.0 migration, we cannot access manifest at this time,
+    // because of legacy smack label. We need to register security context first
+    // to label files in external image.
+    if (!RegisterSecurityContext(mainapp_id, pkgid, {}, "3.0",
+        context_->pkg_path.get(), uid, {}, false, &error_message)) {
+      LOG(ERROR) << "error_message: " << error_message;
+      on_error(Status::SECURITY_ERROR, error_message);
+    }
+  }
+
   if (!RegisterSecurityContextForPathExternalOnly(pkgid,
                         context_->pkg_type.get(), context_->pkg_path.get(),
                         uid, &error_message)) {
@@ -87,6 +101,7 @@ Step::Status StepMigrateLegacyExtImage::process() {
   }
 
   LOG(DEBUG) << "Security context installed";
+
   return Status::OK;
 }