From 415aba0c2bee545caaf7e39020d10d483478be7d Mon Sep 17 00:00:00 2001 From: Ilho Kim Date: Wed, 7 Dec 2022 17:13:41 +0900 Subject: [PATCH] Block different type installation with same pkgid Change-Id: Ia33f3be69f1441b5ec79c0a0d9a5fe9f9eca9062 Signed-off-by: Ilho Kim --- src/common/pkgmgr_interface.cc | 4 ++ src/common/pkgmgr_interface.h | 8 ++++ src/common/step/configuration/step_configure.cc | 52 +++++++++++++++++++++++-- src/common/step/configuration/step_configure.h | 2 + src/common/step/pkgmgr/step_check_removable.cc | 10 ----- 5 files changed, 63 insertions(+), 13 deletions(-) diff --git a/src/common/pkgmgr_interface.cc b/src/common/pkgmgr_interface.cc index 184dfaf..a754585 100644 --- a/src/common/pkgmgr_interface.cc +++ b/src/common/pkgmgr_interface.cc @@ -152,6 +152,10 @@ void PkgMgrInterface::AddAppQueryInterface( query_interface_map_.emplace(idx, interface); } +std::shared_ptr PkgMgrInterface::GetAppQueryInterface() { + return query_interface_; +} + RequestType PkgMgrInterface::GetRequestType(int idx) const { // These type could be determined even if there are no query_interface_. switch (pkgmgr_installer_get_request_type(pi_)) { diff --git a/src/common/pkgmgr_interface.h b/src/common/pkgmgr_interface.h index ded0faf..e085018 100644 --- a/src/common/pkgmgr_interface.h +++ b/src/common/pkgmgr_interface.h @@ -86,6 +86,14 @@ class PkgMgrInterface { std::shared_ptr interface); /** + * Get AppQueryInterface for current request + * + * \return AppQueryInterface ptr if current AppQueryInterface exist. + * Otherwise, return null shared_ptr + */ + std::shared_ptr GetAppQueryInterface(); + + /** * Returns Request type passed from pkgmgr_installer * * \param idx index of request diff --git a/src/common/step/configuration/step_configure.cc b/src/common/step/configuration/step_configure.cc index 2a3d052..6608e03 100644 --- a/src/common/step/configuration/step_configure.cc +++ b/src/common/step/configuration/step_configure.cc @@ -28,6 +28,8 @@ namespace configuration { const char kStrEmpty[] = ""; const char kAppFWUser[] = "app_fw"; +const char kRpmPkgType[] = "rpm"; +const char kRpmInstaller[] = "tpk"; StepConfigure::StepConfigure(InstallerContext* context, PkgMgrPtr pkgmgr) : Step(context), @@ -48,13 +50,15 @@ Step::Status StepConfigure::process() { RequestType request_type = context_->request_type.get(); switch (request_type) { case RequestType::Install: - case RequestType::Update: + case RequestType::Update: { context_->file_path.set(pkgmgr_->GetRequestInfo(context_->index.get())); if (!pkgmgr_->GetTepPath().empty()) { context_->tep_path.set(pkgmgr_->GetTepPath()); context_->is_tep_move.set(pkgmgr_->GetIsTepMove()); } + context_->pkgid.set(GetPkgIdFromFile()); break; + } case RequestType::PartialUninstall: case RequestType::Uninstall: if (request_type == RequestType::PartialUninstall) @@ -88,13 +92,15 @@ Step::Status StepConfigure::process() { pkgmgr_->GetRecoveryCleanup())); break; case RequestType::MountInstall: - case RequestType::MountUpdate: + case RequestType::MountUpdate: { context_->file_path.set(pkgmgr_->GetRequestInfo(context_->index.get())); if (!pkgmgr_->GetTepPath().empty()) { context_->tep_path.set(pkgmgr_->GetTepPath()); context_->is_tep_move.set(pkgmgr_->GetIsTepMove()); } + context_->pkgid.set(GetPkgIdFromFile()); break; + } case RequestType::ManifestPartialInstall: case RequestType::ManifestPartialUpdate: case RequestType::ManifestDirectInstall: @@ -112,13 +118,15 @@ Step::Status StepConfigure::process() { context_->xml_path.set(xml_path); break; } - case RequestType::ReadonlyUpdateInstall: + case RequestType::ReadonlyUpdateInstall: { context_->file_path.set(pkgmgr_->GetRequestInfo(context_->index.get())); if (!pkgmgr_->GetTepPath().empty()) { context_->tep_path.set(pkgmgr_->GetTepPath()); context_->is_tep_move.set(pkgmgr_->GetIsTepMove()); } + context_->pkgid.set(GetPkgIdFromFile()); break; + } case RequestType::ReadonlyUpdateUninstall: { context_->pkgid.set(pkgmgr_->GetRequestInfo(context_->index.get())); bf::path original_path = @@ -145,6 +153,9 @@ Step::Status StepConfigure::process() { return Status::CONFIG_ERROR; } + if (!CheckInvalidBackendUsage()) + return Status::OPERATION_NOT_ALLOWED; + LOG(INFO) << "Request Type: " << GetRequestTypeString(request_type); return Status::OK; @@ -286,5 +297,40 @@ void StepConfigure::SetupMoveType() { } } +std::string StepConfigure::GetPkgIdFromFile() { + auto app_query_interface = pkgmgr_->GetAppQueryInterface(); + if (!app_query_interface) + return ""; + + return app_query_interface->GetPkgId( + pkgmgr_->GetRequestInfo(context_->index.get())); +} + +bool StepConfigure::CheckInvalidBackendUsage() { + if (context_->pkgid.get().empty()) + return true; + + PkgQueryInterface pkg_query(context_->pkgid.get().c_str(), + context_->uid.get()); + if (!pkg_query.IsValid()) { + LOG(INFO) << "pkg[" << context_->pkgid.get() + << "] is not installed, skip checking backend with installed pkg"; + return true; + } + + const std::string& backend_type = context_->pkg_type.get(); + std::string installed_pkg_type = pkg_query.Type(); + if (installed_pkg_type == kRpmPkgType) + installed_pkg_type = kRpmInstaller; + + if (installed_pkg_type != backend_type) { + LOG(ERROR) << "Wrong use of backend : package's type [" << pkg_query.Type() + << "] mismatched backend [" << backend_type << "]"; + return false; + } + + return true; +} + } // namespace configuration } // namespace common_installer diff --git a/src/common/step/configuration/step_configure.h b/src/common/step/configuration/step_configure.h index b13a6b6..c5ff866 100644 --- a/src/common/step/configuration/step_configure.h +++ b/src/common/step/configuration/step_configure.h @@ -69,6 +69,8 @@ class StepConfigure : public Step { void SetupSkipCheckReference(); void SetupSkipOptimization(); void SetupMoveType(); + std::string GetPkgIdFromFile(); + bool CheckInvalidBackendUsage(); PkgMgrPtr pkgmgr_; diff --git a/src/common/step/pkgmgr/step_check_removable.cc b/src/common/step/pkgmgr/step_check_removable.cc index 2ab1e2f..caf7c73 100644 --- a/src/common/step/pkgmgr/step_check_removable.cc +++ b/src/common/step/pkgmgr/step_check_removable.cc @@ -36,16 +36,6 @@ Step::Status StepCheckRemovable::process() { return Status::OPERATION_NOT_ALLOWED; } - std::string pkg_type = pkg_query.Type(); - // rpm package installed by tpk-backend - if (pkg_type == "rpm") - pkg_type = "tpk"; - if (pkg_type != context_->pkg_type.get()) { - LOG(ERROR) << "Wrong use of backend : package's type [" << pkg_query.Type() - << "] mismatched backend [" << context_->pkg_type.get() << "]"; - return Status::OPERATION_NOT_ALLOWED; - } - return Status::OK; } -- 2.7.4