Grant permission for /bin and /lib path 98/70998/5 accepted/tizen/common/20160525.160015 accepted/tizen/ivi/20160525.235204 accepted/tizen/mobile/20160525.235217 accepted/tizen/tv/20160525.235201 accepted/tizen/wearable/20160525.235137 submit/tizen/20160525.055233
authorArkadiusz Szulakiewicz <a.szulakiewi@partner.samsung.com>
Mon, 23 May 2016 14:04:31 +0000 (16:04 +0200)
committerjongmyeongko <jongmyeong.ko@samsung.com>
Wed, 25 May 2016 05:13:10 +0000 (14:13 +0900)
Change-Id: If375ff26f58cd562ba16e12ccaa11aa5c06bebef
Signed-off-by: jongmyeongko <jongmyeong.ko@samsung.com>
src/tpk/CMakeLists.txt
src/tpk/step/filesystem/step_grant_permission.cc [new file with mode: 0644]
src/tpk/step/filesystem/step_grant_permission.h [new file with mode: 0644]
src/tpk/tpk_installer.cc

index 8f329688243f2eff4c0df2d400d435e5e2972d42..ae8bd82b714245912e5a238f8a1895aad33a06d4 100644 (file)
@@ -2,6 +2,7 @@ SET(SRCS
   step/configuration/step_parse_preload.cc
   step/filesystem/step_check_pkg_directory_path.cc
   step/filesystem/step_create_symbolic_link.cc
+  step/filesystem/step_grant_permission.cc
   step/filesystem/step_tpk_patch_icons.cc
   step/filesystem/step_tpk_prepare_package_directory.cc
   step/filesystem/step_tpk_update_package_directory.cc
diff --git a/src/tpk/step/filesystem/step_grant_permission.cc b/src/tpk/step/filesystem/step_grant_permission.cc
new file mode 100644 (file)
index 0000000..f12487c
--- /dev/null
@@ -0,0 +1,101 @@
+// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by an apache-2.0 license that can be
+// found in the LICENSE file.
+
+#include "tpk/step/filesystem/step_grant_permission.h"
+
+#include <boost/filesystem/operations.hpp>
+#include <boost/filesystem/path.hpp>
+#include <boost/range/iterator_range.hpp>
+#include <boost/system/error_code.hpp>
+
+#include <common/utils/file_util.h>
+
+namespace bf = boost::filesystem;
+namespace bs = boost::system;
+namespace ci = common_installer;
+
+namespace tpk {
+namespace filesystem {
+
+ci::Step::Status StepTpkGrantPermission::precheck() {
+  if (context_->pkgid.get().empty()) {
+    LOG(ERROR) << "Pkgid is not set";
+    return Status::INVALID_VALUE;
+  }
+  return Status::OK;
+}
+
+ci::Step::Status StepTpkGrantPermission::process() {
+  Status status = Status::OK;
+  context_->pkg_path.set(
+      context_->root_application_path.get() / context_->pkgid.get());
+
+  bf::path app_root = context_->pkg_path.get();
+  for (auto& entry :
+      boost::make_iterator_range(bf::directory_iterator(app_root), {})) {
+    auto path = entry.path();
+
+    if (bf::is_directory(path) && path.filename() == "bin") {
+      for (auto& entry :
+          boost::make_iterator_range(bf::directory_iterator(path), {})) {
+        if (bf::is_regular_file(path)) {
+          auto permission = bf::perms::owner_all |
+              bf::perms::group_read | bf::perms::group_exe |
+              bf::perms::others_read | bf::perms::others_exe;
+          if (!ci::SetDirPermissions(path, permission)) {
+            LOG(ERROR) << "Grand permission error" << " path: " << path
+                << " permission: " << permission;
+            return Status::ERROR; /* temp error, TODO */
+          }
+        }
+      }
+      continue;
+    }
+
+    if (bf::is_directory(path) && path.filename() == "lib") {
+      for (auto& entry :
+          boost::make_iterator_range(bf::directory_iterator(path), {})) {
+        if (bf::is_regular_file(path)) {
+          auto permission = bf::perms::owner_read | bf::perms::owner_write |
+              bf::perms::group_read | bf::perms::others_read;
+          if (!ci::SetDirPermissions(path, permission)) {
+            LOG(ERROR) << "Grand permission error" << " path: " << path
+                << " permission: " << permission;
+            return Status::ERROR;
+          }
+        }
+      }
+      continue;
+    }
+
+    if (bf::is_directory(path)) {
+      auto permission = bf::perms::owner_all |
+          bf::perms::group_read | bf::perms::group_exe |
+          bf::perms::others_read | bf::perms::others_exe;
+      if (!ci::SetDirPermissions(path, permission)) {
+        LOG(ERROR) << "Grand permission error" << " path: " << path
+            << " permission: " << permission;
+        return Status::ERROR;
+      }
+      continue;
+    }
+
+    if (bf::is_regular_file(path)) {
+      auto permission = bf::perms::owner_read | bf::perms::owner_write |
+          bf::perms::group_read | bf::perms::others_read;
+      if (!ci::SetDirPermissions(path, permission)) {
+        LOG(ERROR) << "Grand permission error" << " path: " << path
+            << " permission: " << permission;
+        return Status::ERROR;
+      }
+      continue;
+    }
+  }
+
+  return status;
+}
+
+}  // namespace filesystem
+}  // namespace tpk
+
diff --git a/src/tpk/step/filesystem/step_grant_permission.h b/src/tpk/step/filesystem/step_grant_permission.h
new file mode 100644 (file)
index 0000000..2dac339
--- /dev/null
@@ -0,0 +1,37 @@
+// Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by an apache-2.0 license that can be
+// found in the LICENSE file.
+
+
+#ifndef TPK_STEP_FILESYSTEM_TPK_GRANT_PERMISSION_H_
+#define TPK_STEP_FILESYSTEM_TPK_GRANT_PERMISSION_H_
+
+#include <manifest_parser/utils/logging.h>
+
+#include <string>
+
+#include "common/installer_context.h"
+#include "common/step/step.h"
+
+namespace tpk {
+namespace filesystem {
+
+/**
+ * \brief Step responsible for granting permissions to /bin, /lib
+ */
+class StepTpkGrantPermission : public common_installer::Step {
+ public:
+  using Step::Step;
+
+  Status process() override;
+  Status undo() override { return Status::OK; }
+  Status clean() override { return Status::OK; }
+  Status precheck() override;
+
+  SCOPE_LOG_TAG(GrantPermission)
+};
+
+}  // namespace filesystem
+}  // namespace tpk
+
+#endif  // TPK_STEP_FILESYSTEM_TPK_GRANT_PERMISSION_H_
index c7af87d0b1849a90039a5315a6e784fd25f2dc91..d6b301e65cc4bc1ecac17496dee7c607eddacecd 100644 (file)
@@ -54,6 +54,7 @@
 #include "tpk/step/configuration/step_parse_preload.h"
 #include "tpk/step/filesystem/step_create_symbolic_link.h"
 #include "tpk/step/filesystem/step_check_pkg_directory_path.h"
+#include "tpk/step/filesystem/step_grant_permission.h"
 #include "tpk/step/filesystem/step_tpk_patch_icons.h"
 #include "tpk/step/filesystem/step_tpk_prepare_package_directory.h"
 #include "tpk/step/filesystem/step_tpk_update_package_directory.h"
@@ -141,6 +142,7 @@ void TpkInstaller::InstallSteps() {
   AddStep<ci::security::StepRegisterSecurity>();
   AddStep<tpk::pkgmgr::StepConvertXml>();
   AddStep<tpk::pkgmgr::StepManifestAdjustment>();
+  AddStep<tpk::filesystem::StepTpkGrantPermission>();
   AddStep<ci::pkgmgr::StepRegisterApplication>();
   AddStep<ci::pkgmgr::StepRunParserPlugin>(
       ci::Plugin::ActionType::Install);
@@ -174,6 +176,7 @@ void TpkInstaller::UpdateSteps() {
   AddStep<ci::filesystem::StepCreateIcons>();
   AddStep<ci::security::StepUpdateSecurity>();
   AddStep<tpk::pkgmgr::StepConvertXml>();
+  AddStep<tpk::filesystem::StepTpkGrantPermission>();
   AddStep<tpk::pkgmgr::StepManifestAdjustment>();
   AddStep<ci::pkgmgr::StepUpdateApplication>();
   AddStep<ci::pkgmgr::StepRunParserPlugin>(ci::Plugin::ActionType::Upgrade);
@@ -224,6 +227,7 @@ void TpkInstaller::ReinstallSteps() {
   AddStep<ci::filesystem::StepCreateIcons>();
   AddStep<ci::security::StepUpdateSecurity>();
   AddStep<tpk::pkgmgr::StepConvertXml>();
+  AddStep<tpk::filesystem::StepTpkGrantPermission>();
   AddStep<tpk::pkgmgr::StepManifestAdjustment>();
   AddStep<ci::pkgmgr::StepUpdateApplication>();
   AddStep<ci::pkgmgr::StepRunParserPlugin>(ci::Plugin::ActionType::Upgrade);
@@ -295,6 +299,7 @@ void TpkInstaller::MountInstallSteps() {
   AddStep<tpk::pkgmgr::StepConvertXml>();
   AddStep<tpk::pkgmgr::StepManifestAdjustment>();
   AddStep<ci::pkgmgr::StepRegisterApplication>();
+  AddStep<tpk::filesystem::StepTpkGrantPermission>();
   AddStep<ci::pkgmgr::StepRunParserPlugin>(
       ci::Plugin::ActionType::Install);
   AddStep<ci::filesystem::StepCreatePerUserStorageDirectories>();
@@ -329,6 +334,7 @@ void TpkInstaller::MountUpdateSteps() {
   AddStep<tpk::pkgmgr::StepConvertXml>();
   AddStep<tpk::pkgmgr::StepManifestAdjustment>();
   AddStep<ci::pkgmgr::StepUpdateApplication>();
+  AddStep<tpk::filesystem::StepTpkGrantPermission>();
   AddStep<ci::pkgmgr::StepRunParserPlugin>(ci::Plugin::ActionType::Upgrade);
 }
 
@@ -348,6 +354,7 @@ void TpkInstaller::ManifestDirectInstallSteps() {
   AddStep<ci::security::StepRollbackInstallationSecurity>();
   AddStep<ci::security::StepRegisterSecurity>();
   AddStep<ci::pkgmgr::StepRegisterApplication>();
+  AddStep<tpk::filesystem::StepTpkGrantPermission>();
   AddStep<ci::pkgmgr::StepRunParserPlugin>(ci::Plugin::ActionType::Install);
   AddStep<ci::filesystem::StepCreatePerUserStorageDirectories>();
 }
@@ -368,6 +375,7 @@ void TpkInstaller::ManifestDirectUpdateSteps() {
   AddStep<ci::security::StepRollbackInstallationSecurity>();
   AddStep<ci::security::StepRegisterSecurity>();
   AddStep<ci::pkgmgr::StepUpdateApplication>();
+  AddStep<tpk::filesystem::StepTpkGrantPermission>();
   AddStep<ci::pkgmgr::StepRunParserPlugin>(ci::Plugin::ActionType::Upgrade);
 }