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_register_security.h"
7 #include <boost/filesystem.hpp>
10 #include "common/security_registration.h"
12 namespace common_installer {
15 Step::Status StepRegisterSecurity::precheck() {
16 if (context_->GetPkgPath().empty()) {
17 LOG(ERROR) << "pkg_path attribute is empty";
18 return Step::Status::INVALID_VALUE;
20 if (!boost::filesystem::exists(context_->GetPkgPath())) {
21 LOG(ERROR) << "pkg_path ("
22 << context_->GetPkgPath()
23 << ") path does not exist";
24 return Step::Status::INVALID_VALUE;
27 if (context_->pkgid.get().empty()) {
28 LOG(ERROR) << "pkgid attribute is empty";
29 return Step::Status::INVALID_VALUE;
32 if (!context_->manifest_data.get()) {
33 LOG(ERROR) << "manifest_data attribute is empty";
34 return Step::Status::INVALID_VALUE;
37 return Step::Status::OK;
40 Step::Status StepRegisterSecurity::process() {
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(Status::SECURITY_ERROR, error_message);
50 return Status::SECURITY_ERROR;
52 if (context_->partial_rw.get())
54 if (!RegisterSecurityContextForPath(
55 context_->pkgid.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(Status::SECURITY_ERROR, error_message);
61 return Status::SECURITY_ERROR;
63 LOG(DEBUG) << "Security context installed";
67 void StepRegisterSecurity::AddRecoveryInfo() {
68 recovery::RecoveryFile* recovery_file =
69 context_->recovery_info.get().recovery_file.get();
73 recovery_file->set_security_operation_done(true);
74 recovery_file->WriteAndCommitFileContent();
77 } // namespace security
78 } // namespace common_installer