Revert "In case of partial-rw requset, register security context for rwdata path...
[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 <boost/filesystem.hpp>
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_->pkg_path.get().empty()) {
17     LOG(ERROR) << "pkg_path attribute is empty";
18     return Step::Status::INVALID_VALUE;
19   }
20   if (!boost::filesystem::exists(context_->pkg_path.get())) {
21     LOG(ERROR) << "pkg_path ("
22                << context_->pkg_path.get()
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   std::string error_message;
42   if (!RegisterSecurityContextForManifest(
43       context_->pkgid.get(), context_->pkg_path.get(), context_->uid.get(),
44       &context_->certificate_info.get(), context_->manifest_data.get(),
45       context_->cross_app_rules.get(), &error_message)) {
46     if (!error_message.empty()) {
47       LOG(ERROR) << "error_message: " << error_message;
48       on_error(Status::SECURITY_ERROR, error_message);
49     }
50     return Status::SECURITY_ERROR;
51   }
52   if (!RegisterSecurityContextForPath(
53       context_->pkgid.get(), context_->pkg_path.get(), context_->uid.get(),
54       context_->is_readonly_package.get(), &error_message)) {
55     if (!error_message.empty()) {
56       LOG(ERROR) << "error_message: " << error_message;
57       on_error(Status::SECURITY_ERROR, error_message);
58     }
59     return Status::SECURITY_ERROR;
60   }
61   LOG(DEBUG) << "Security context installed";
62   return Status::OK;
63 }
64
65 }  // namespace security
66 }  // namespace common_installer