Fix for platform upgrade 89/86789/11
authorJunghyun Yeon <jungh.yeon@samsung.com>
Mon, 5 Sep 2016 02:02:33 +0000 (11:02 +0900)
committerJunghyun Yeon <jungh.yeon@samsung.com>
Fri, 9 Sep 2016 05:43:58 +0000 (22:43 -0700)
Related changes
[pkgmgr-tool] : https://review.tizen.org/gerrit/#/c/83327/
[tpk-backend] : https://review.tizen.org/gerrit/#/c/86846/
[wgt-backend] : https://review.tizen.org/gerrit/#/c/87472/

Change-Id: I7e44bb7233ca4318fe8bb11c81e8d69c06e56da1
Signed-off-by: Junghyun Yeon <jungh.yeon@samsung.com>
src/common/certificate_validation.cc
src/common/step/configuration/step_configure.cc
src/common/step/configuration/step_parse_manifest.cc
src/common/step/pkgmgr/step_kill_apps.cc
src/common/step/security/step_check_signature.cc

index 23f9df4..e94d61d 100644 (file)
@@ -208,7 +208,8 @@ bool ValidateSignatures(const bf::path& base_path,
   bool distributor_signatures = std::any_of(
       signature_files.begin(), signature_files.end(), CheckDistSignature);
 
-  if (!is_preload && (!author_signatures || !distributor_signatures)) {
+  /* For platform update from 2.4.  signature1.xml of user app has deleted */
+  if (getuid() != 0 && (!author_signatures || !distributor_signatures)) {
     LOG(ERROR) << "Author or distribuor signature is missing.";
     return false;
   }
index 47f4852..1e8f390 100644 (file)
@@ -18,6 +18,7 @@
 
 #include "common/request.h"
 #include "common/utils/file_util.h"
+#include "common/utils/user_util.h"
 
 namespace bf = boost::filesystem;
 
@@ -25,6 +26,7 @@ namespace common_installer {
 namespace configuration {
 
 const char kStrEmpty[] = "";
+const char kAppFWUser[] = "app_fw";
 
 StepConfigure::StepConfigure(InstallerContext* context, PkgMgrPtr pkgmgr)
     : Step(context),
@@ -148,29 +150,27 @@ Step::Status StepConfigure::precheck() {
   context_->uid.set(pkgmgr_->GetUid());
   if (getuid() == 0) {
     if (pkgmgr_->GetRequestType() == RequestType::ManifestDirectInstall ||
-        pkgmgr_->GetRequestType() == RequestType::ManifestDirectUpdate) {
-      LOG(INFO) << "Allowing installation from root user for "
-                   "manifest direct mode.";
+        pkgmgr_->GetRequestType() == RequestType::ManifestDirectUpdate ||
+        pkgmgr_->GetRequestType() == RequestType::DisablePkg ||
+        pkgmgr_->GetRequestType() == RequestType::EnablePkg) {
+      LOG(INFO) << "Allowing operation for root user";
     } else if (context_->is_preload_request.get()) {
-      LOG(INFO) << "Allowing installation from root user for "
-                   "preload request mode.";
+      LOG(INFO) << "Allowing preload request mode for root user";
     } else {
       LOG(ERROR) << "App-installer should not run with superuser!";
       return Status::OPERATION_NOT_ALLOWED;
     }
-  } else {
-    if (pkgmgr_->GetRequestType() == RequestType::ManifestDirectInstall ||
-        pkgmgr_->GetRequestType() == RequestType::ManifestDirectUpdate) {
-      if (context_->is_preload_request.get()) {
-        LOG(ERROR) << "Direct manifest installation/update that is run from "
-                      "non-root user cannot be a preload request";
-        return Status::OPERATION_NOT_ALLOWED;
-      }
-    } else if (context_->is_preload_request.get()) {
-      LOG(ERROR) << "Non-root user cannot request preload request mode.";
-      return Status::OPERATION_NOT_ALLOWED;
-    }
   }
+
+  boost::optional<uid_t> appfw_uid= GetUidByUserName(kAppFWUser);
+  if (!appfw_uid)
+    return Status::ERROR;
+
+  if (getuid() != *appfw_uid) {
+    LOG(ERROR) << "App-installer should not run with normal user!";
+    return Status::OPERATION_NOT_ALLOWED;
+  }
+
   return Status::OK;
 }
 
index 5d24cd1..3e4f398 100644 (file)
@@ -112,6 +112,11 @@ bool StepParseManifest::LocateConfigFile() {
       xml_path += ".xml";
       context_->xml_path.set(xml_path);
       manifest = context_->xml_path.get();
+      if (!boost::filesystem::exists(manifest)) {
+        /* This routine has added for platform update */
+        manifest = context_->unpacked_dir_path.get();
+        manifest /= kManifestFileName;
+      }
       break;
     }
     case ManifestLocation::PACKAGE: {
@@ -185,16 +190,12 @@ bool StepParseManifest::FillPackageInfo(manifest_x* manifest) {
 
   if (pkg_info->type().empty()) {
     common_installer::RequestType req_type = context_->request_type.get();
-    if (req_type == RequestType::ManifestDirectInstall ||
-        req_type == RequestType::ManifestDirectUpdate) {
+    if ((req_type == RequestType::ManifestDirectInstall ||
+        req_type == RequestType::ManifestDirectUpdate) &&
+        context_->is_preload_request.get())
       manifest->type = strdup("rpm");
-      if (!context_->is_preload_request.get()) {
-        LOG(ERROR) << "Non-preload rpm installation not allowed";
-        return false;
-      }
-    } else {
+    else
       manifest->type = strdup("tpk");
-    }
   } else {
     manifest->type = strdup(pkg_info->type().c_str());
   }
index 24e29a5..d1ed25a 100644 (file)
@@ -43,7 +43,7 @@ bool KillApp(const std::string& appid, const uid_t uid) {
   if (uid == 0 || uid == tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)) {
     ret = sd_get_uids(&uids);
     if (ret < 0 || (ret == 0 || uids == nullptr)) {
-      LOG(ERROR) << "Failed to get uids [" << ret << "]";
+      LOG(DEBUG) << "Failed to get uids [" << ret << "]";
       return false;
     }
 
index 6ddcc98..9e2b3f8 100644 (file)
@@ -121,6 +121,10 @@ Step::Status StepCheckSignature::process() {
   if (is_preload)
     level = PrivilegeLevel::PLATFORM;
 
+  /* for update of user apps in 2.4 */
+  if (getuid() == 0 && level == PrivilegeLevel::UNTRUSTED)
+    level = PrivilegeLevel::PUBLIC;
+
   if (level == PrivilegeLevel::UNTRUSTED) {
     std::string error_message =
         "Unsigned applications can not be installed";