7e1614d570ce3c849023d2c021b5e53b23714154
[platform/core/appfw/app-installers.git] / src / common / step / security / step_rollback_deinstallation_security.cc
1 // Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
2 // Use of this source code is governed by an apache-2.0 license that can be
3 // found in the LICENSE file.
4
5 #include "common/step/security/step_rollback_deinstallation_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 StepRollbackDeinstallationSecurity::precheck() {
16   if (context_->pkgid.get().empty()) {
17     LOG(ERROR) << "pkgid attribute is empty";
18     return Step::Status::PACKAGE_NOT_FOUND;
19   }
20   if (!context_->manifest_data.get()) {
21     LOG(ERROR) << "manifest_data attribute is empty";
22     return Step::Status::MANIFEST_NOT_FOUND;
23   }
24
25   return Step::Status::OK;
26 }
27
28 Step::Status StepRollbackDeinstallationSecurity::undo() {
29   std::string error_message;
30   if (!RegisterSecurityContextForManifest(context_, &error_message)) {
31     LOG(ERROR) << "Failure on re-installing security context for app "
32                << context_->pkgid.get();
33     if (!error_message.empty()) {
34       LOG(ERROR) << "error_message: " << error_message;
35     }
36     return Status::SECURITY_ERROR;
37   }
38   if (!RegisterSecurityContextForPath(
39       context_->pkgid.get(), context_->GetPkgPath(), context_->uid.get(),
40       context_->is_readonly_package.get(), &error_message)) {
41     if (!error_message.empty()) {
42       LOG(ERROR) << "error_message: " << error_message;
43       on_error(Status::SECURITY_ERROR, error_message);
44     }
45     return Status::SECURITY_ERROR;
46   }
47   LOG(DEBUG) << "Security context installed";
48   return Status::OK;
49 }
50
51 }  // namespace security
52 }  // namespace common_installer