f00f4b2027af90180a88a32478acc368dc40b1b3
[platform/core/appfw/app-installers.git] / src / common / step / security / step_update_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_update_security.h"
6
7 #include <string>
8
9 #include "common/security_registration.h"
10
11 namespace common_installer {
12 namespace security {
13
14 Step::Status StepUpdateSecurity::process() {
15   std::string error_message;
16   if (!RegisterSecurityContextForManifest(context_, &error_message)) {
17     if (!error_message.empty()) {
18       LOG(ERROR) << "error_message: " << error_message;
19       on_error(Status::SECURITY_ERROR, error_message);
20     }
21     return Status::SECURITY_ERROR;
22   }
23   if (context_->request_type.get() != RequestType::ReadonlyUpdateUninstall) {
24     if (!RegisterSecurityContextForPath(
25         context_->pkgid.get(), context_->GetPkgPath(), context_->uid.get(),
26         context_->is_readonly_package.get(), &error_message)) {
27       if (!error_message.empty()) {
28         LOG(ERROR) << "error_message: " << error_message;
29         on_error(Status::SECURITY_ERROR, error_message);
30       }
31       return Status::SECURITY_ERROR;
32     }
33   }
34   LOG(DEBUG) << "Security context updated";
35   return Status::OK;
36 }
37
38 Step::Status StepUpdateSecurity::undo() {
39   std::string error_message;
40   if (!RegisterSecurityContextForManifest(context_, &error_message)) {
41     if (!error_message.empty()) {
42       LOG(ERROR) << "error_message: " << error_message;
43     }
44     return Status::SECURITY_ERROR;
45   }
46   if (!RegisterSecurityContextForPath(
47       context_->pkgid.get(), context_->GetPkgPath(), context_->uid.get(),
48       context_->is_readonly_package.get(), &error_message)) {
49     if (!error_message.empty()) {
50       LOG(ERROR) << "error_message: " << error_message;
51       on_error(Status::SECURITY_ERROR, error_message);
52     }
53     return Status::SECURITY_ERROR;
54   }
55   LOG(DEBUG) << "Security context reverted";
56   return Status::OK;
57 }
58
59 }  // namespace security
60 }  // namespace common_installer