1 // Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
2 // Use of this source code is governed by a apache 2.0 license that can be
3 // found in the LICENSE file.
5 #include "common/step/security/step_update_security.h"
9 #include "common/security_registration.h"
11 namespace common_installer {
14 Step::Status StepUpdateSecurity::process() {
17 std::string error_message;
18 if (!RegisterSecurityContextForManifest(context_, &error_message)) {
19 if (!error_message.empty()) {
20 LOG(ERROR) << "error_message: " << error_message;
21 on_error_->on_error(Status::SECURITY_ERROR, error_message);
23 return Status::SECURITY_ERROR;
25 if (context_->request_type.get() != RequestType::ReadonlyUpdateUninstall) {
26 if (!RegisterSecurityContextForPath(context_->pkgid.get(),
27 context_->pkg_type.get(), context_->GetPkgPath(), context_->uid.get(),
28 context_->is_readonly_package.get(), &error_message)) {
29 if (!error_message.empty()) {
30 LOG(ERROR) << "error_message: " << error_message;
31 on_error_->on_error(Status::SECURITY_ERROR, error_message);
33 return Status::SECURITY_ERROR;
36 LOG(DEBUG) << "Security context updated";
40 Step::Status StepUpdateSecurity::undo() {
41 std::string error_message;
42 if (!RegisterSecurityContextForManifest(context_, &error_message)) {
43 if (!error_message.empty()) {
44 LOG(ERROR) << "error_message: " << error_message;
46 return Status::SECURITY_ERROR;
48 if (!RegisterSecurityContextForPath(context_->pkgid.get(),
49 context_->pkg_type.get(), context_->GetPkgPath(), context_->uid.get(),
50 context_->is_readonly_package.get(), &error_message)) {
51 if (!error_message.empty()) {
52 LOG(ERROR) << "error_message: " << error_message;
53 on_error_->on_error(Status::SECURITY_ERROR, error_message);
55 return Status::SECURITY_ERROR;
57 LOG(DEBUG) << "Security context reverted";
61 void StepUpdateSecurity::AddRecoveryInfo() {
62 recovery::RecoveryFile* recovery_file =
63 context_->recovery_info.get().recovery_file.get();
67 recovery_file->set_security_operation_done(true);
68 recovery_file->WriteAndCommitFileContent();
71 } // namespace security
72 } // namespace common_installer