1 // Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
2 // Use of this source code is governed by an apache-2.0 license that can be
3 // found in the LICENSE file.
5 #include "common/step/security/step_recover_security.h"
7 #include <boost/filesystem.hpp>
10 #include "common/security_registration.h"
12 namespace common_installer {
15 bool StepRecoverSecurity::Check(bool is_update) {
16 if (context_->GetPkgPath().empty())
18 if (!boost::filesystem::exists(context_->GetPkgPath()) && is_update)
20 if (context_->pkgid.get().empty())
25 Step::Status StepRecoverSecurity::RecoveryNew() {
28 recovery::RecoveryFile* recovery_file =
29 context_->recovery_info.get().recovery_file.get();
30 if (!recovery_file->security_operation_done()) {
31 LOG(DEBUG) << "security_operation_done false skip recover security";
34 std::string error_message;
35 if (!context_->manifest_data.get()) {
36 if (!UnregisterSecurityContextForPkgId(context_->pkgid.get(),
37 context_->pkg_type.get(), context_->uid.get(), &error_message, true)) {
38 LOG(ERROR) << "Unsuccessful install";
39 if (!error_message.empty()) {
40 LOG(ERROR) << "error_message: " << error_message;
41 on_error(Status::RECOVERY_ERROR, error_message);
43 return Status::RECOVERY_ERROR;
45 } else if (!UnregisterSecurityContextForManifest(
46 context_->pkgid.get(), context_->pkg_type.get(), context_->uid.get(),
47 context_->manifest_data.get(), &error_message)) {
48 LOG(ERROR) << "Unsuccessful install";
49 if (!error_message.empty()) {
50 LOG(ERROR) << "error_message: " << error_message;
51 on_error(Status::RECOVERY_ERROR, error_message);
53 return Status::RECOVERY_ERROR;
58 Step::Status StepRecoverSecurity::RecoveryUpdate() {
60 LOG(ERROR) << "Invalid parameters";
61 return Status::INVALID_VALUE;
63 recovery::RecoveryFile* recovery_file =
64 context_->recovery_info.get().recovery_file.get();
65 if (!recovery_file->security_operation_done()) {
66 LOG(DEBUG) << "security_operation_done false skip recover security";
69 std::string error_message;
70 if (!RegisterSecurityContextForManifest(context_, &error_message)) {
71 LOG(ERROR) << "Unsuccessful update";
72 if (!error_message.empty()) {
73 LOG(ERROR) << "error_message: " << error_message;
74 on_error(Status::RECOVERY_ERROR, error_message);
76 return Status::RECOVERY_ERROR;
79 if (!HasOwnerRwOtherRoPaths(context_->GetPkgPath()))
82 if (!RegisterSecurityContextForPath(
83 context_->pkgid.get(), context_->GetPkgPath(), context_->uid.get(),
84 context_->is_readonly_package.get(), &error_message)) {
85 if (!error_message.empty()) {
86 LOG(ERROR) << "error_message: " << error_message;
87 on_error(Status::RECOVERY_ERROR, error_message);
89 return Status::RECOVERY_ERROR;
94 Step::Status StepRecoverSecurity::RecoveryReadonlyUpdateInstall() {
96 LOG(ERROR) << "Invalid parameters";
97 return Status::INVALID_VALUE;
99 recovery::RecoveryFile* recovery_file =
100 context_->recovery_info.get().recovery_file.get();
101 if (!recovery_file->security_operation_done()) {
102 LOG(DEBUG) << "security_operation_done false skip recover security";
105 std::string error_message;
106 if (!RegisterSecurityContextForManifest(context_, &error_message)) {
107 LOG(ERROR) << "Unsuccessful update";
108 if (!error_message.empty()) {
109 LOG(ERROR) << "error_message: " << error_message;
110 on_error(Status::RECOVERY_ERROR, error_message);
112 return Status::RECOVERY_ERROR;
117 } // namespace security
118 } // namespace common_installer