Remove boost dependency
[platform/core/appfw/app-installers.git] / src / common / step / security / step_register_security.cc
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.
4
5 #include "common/step/security/step_register_security.h"
6
7 #include <filesystem>
8 #include <string>
9
10 #include "common/security_registration.h"
11
12 namespace common_installer {
13 namespace security {
14
15 Step::Status StepRegisterSecurity::precheck() {
16   if (context_->GetPkgPath().empty()) {
17     LOG(ERROR) << "pkg_path attribute is empty";
18     return Step::Status::INVALID_VALUE;
19   }
20   if (!std::filesystem::exists(context_->GetPkgPath())) {
21     LOG(ERROR) << "pkg_path ("
22                << context_->GetPkgPath()
23                << ") path does not exist";
24     return Step::Status::INVALID_VALUE;
25   }
26
27   if (context_->pkgid.get().empty()) {
28     LOG(ERROR) << "pkgid attribute is empty";
29     return Step::Status::INVALID_VALUE;
30   }
31
32   if (!context_->manifest_data.get()) {
33     LOG(ERROR) << "manifest_data attribute is empty";
34     return Step::Status::INVALID_VALUE;
35   }
36
37   return Step::Status::OK;
38 }
39
40 Step::Status StepRegisterSecurity::process() {
41   AddRecoveryInfo();
42
43   std::string error_message;
44   if (context_->request_type.get() != RequestType::Move &&
45       !RegisterSecurityContextForManifest(context_, &error_message)) {
46     if (!error_message.empty()) {
47       LOG(ERROR) << "error_message: " << error_message;
48       on_error_->on_error(Status::SECURITY_ERROR, error_message);
49     }
50     return Status::SECURITY_ERROR;
51   }
52   if (context_->partial_rw.get())
53     return Status::OK;
54   if (!RegisterSecurityContextForPath(context_->pkgid.get(),
55       context_->pkg_type.get(), context_->GetPkgPath(), context_->uid.get(),
56       context_->is_readonly_package.get(), &error_message)) {
57     if (!error_message.empty()) {
58       LOG(ERROR) << "error_message: " << error_message;
59       on_error_->on_error(Status::SECURITY_ERROR, error_message);
60     }
61     return Status::SECURITY_ERROR;
62   }
63   LOG(DEBUG) << "Security context installed";
64   return Status::OK;
65 }
66
67 void StepRegisterSecurity::AddRecoveryInfo() {
68   recovery::RecoveryFile* recovery_file =
69       context_->recovery_info.get().recovery_file.get();
70   if (!recovery_file)
71     return;
72
73   recovery_file->set_security_operation_done(true);
74   recovery_file->WriteAndCommitFileContent();
75 }
76
77 }  // namespace security
78 }  // namespace common_installer