Add StepCheckRestriction 58/72958/5
authorSangyoon Jang <s89.jang@samsung.com>
Fri, 3 Jun 2016 08:30:00 +0000 (17:30 +0900)
committerSangyoon Jang <s89.jang@samsung.com>
Tue, 7 Jun 2016 06:51:12 +0000 (23:51 -0700)
Change-Id: If31097047c03df9a5d51ed6a4ced3a220e3781ad
Signed-off-by: Sangyoon Jang <s89.jang@samsung.com>
src/common/CMakeLists.txt
src/common/step/pkgmgr/step_check_restriction.cc [new file with mode: 0644]
src/common/step/pkgmgr/step_check_restriction.h [new file with mode: 0644]

index 45ca2d7..6e7591c 100644 (file)
@@ -55,6 +55,7 @@ SET(SRCS
   step/mount/step_mount_unpacked.cc
   step/mount/step_mount_update.cc
   step/pkgmgr/step_check_removable.cc
+  step/pkgmgr/step_check_restriction.cc
   step/pkgmgr/step_kill_apps.cc
   step/pkgmgr/step_recover_application.cc
   step/pkgmgr/step_register_app.cc
diff --git a/src/common/step/pkgmgr/step_check_restriction.cc b/src/common/step/pkgmgr/step_check_restriction.cc
new file mode 100644 (file)
index 0000000..3b58c72
--- /dev/null
@@ -0,0 +1,78 @@
+// Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by a apache 2.0 license that can be
+// found in the LICENSE file.
+
+#include "common/step/pkgmgr/step_check_restriction.h"
+
+#include <package-manager.h>
+
+#include "common/installer_context.h"
+
+namespace ci = common_installer;
+
+namespace common_installer {
+namespace pkgmgr {
+
+Step::Status StepCheckRestriction::process() {
+  int type;
+  switch (context_->request_type.get()) {
+  case ci::RequestType::Install:
+    type = PM_RESTRICTION_MODE_INSTALL;
+    break;
+  case ci::RequestType::Uninstall:
+    type = PM_RESTRICTION_MODE_UNINSTALL;
+    break;
+  case ci::RequestType::Reinstall:
+    type = PM_RESTRICTION_MODE_REINSTALL;
+    break;
+  case ci::RequestType::Move:
+    type = PM_RESTRICTION_MODE_MOVE;
+    break;
+  default:
+    type = -1;
+    break;
+  }
+
+  if (type < 0)
+    return Status::OK;
+
+  pkgmgr_client* pc = pkgmgr_client_new(PC_REQUEST);
+  if (!pc)
+    return Status::ERROR;
+
+  int mode;
+  int ret = pkgmgr_client_usr_get_pkg_restriction_mode(
+      pc, nullptr, &mode, context_->uid.get());
+  if (ret != PKGMGR_R_OK) {
+    LOG(ERROR) << "Failed to get restriction mode bit";
+    pkgmgr_client_free(pc);
+    return Status::ERROR;
+  }
+
+  if (type & mode) {
+    LOG(ERROR) << "Restricted operation";
+    pkgmgr_client_free(pc);
+    return Status::OPERATION_NOT_ALLOWED;
+  }
+
+  ret = pkgmgr_client_usr_get_pkg_restriction_mode(
+      pc, context_->pkgid.get().c_str(), &mode, context_->uid.get());
+  if (ret != PKGMGR_R_OK) {
+    LOG(ERROR) << "Failed to get restriction mode bit";
+    pkgmgr_client_free(pc);
+    return Status::ERROR;
+  }
+
+  if (type & mode) {
+    LOG(ERROR) << "Restricted operation for pkgid: " << context_->pkgid.get();
+    pkgmgr_client_free(pc);
+    return Status::OPERATION_NOT_ALLOWED;
+  }
+
+  pkgmgr_client_free(pc);
+
+  return Status::OK;
+}
+
+}  // namespace pkgmgr
+}  // namespace common_installer
diff --git a/src/common/step/pkgmgr/step_check_restriction.h b/src/common/step/pkgmgr/step_check_restriction.h
new file mode 100644 (file)
index 0000000..6f4f058
--- /dev/null
@@ -0,0 +1,30 @@
+// Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by a apache 2.0 license that can be
+// found in the LICENSE file.
+
+#ifndef COMMON_STEP_PKGMGR_STEP_CHECK_RESTRICTION_H_
+#define COMMON_STEP_PKGMGR_STEP_CHECK_RESTRICTION_H_
+
+#include <manifest_parser/utils/logging.h>
+
+#include "common/step/step.h"
+
+namespace common_installer {
+namespace pkgmgr {
+
+class StepCheckRestriction : public Step {
+ public:
+  using Step::Step;
+
+  Status process() override;
+  Status clean() override { return Status::OK; }
+  Status undo() override { return Status::OK; }
+  Status precheck() override { return Status::OK; }
+
+  STEP_NAME(CheckRestriction)
+};
+
+}  // namespace pkgmgr
+}  // namespace common_installer
+
+#endif  // COMMON_STEP_PKGMGR_STEP_CHECK_RESTRICTION_H_