2e6f9d383325951b09da30d31f70a283acb8deda
[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 <string>
8
9 #include "common/security_registration.h"
10
11 namespace common_installer {
12 namespace security {
13
14 Step::Status StepRollbackDeinstallationSecurity::precheck() {
15   if (context_->pkgid.get().empty()) {
16     LOG(ERROR) << "pkgid attribute is empty";
17     return Step::Status::PACKAGE_NOT_FOUND;
18   }
19   if (!context_->manifest_data.get()) {
20     LOG(ERROR) << "manifest_data attribute is empty";
21     return Step::Status::MANIFEST_NOT_FOUND;
22   }
23
24   return Step::Status::OK;
25 }
26
27 Step::Status StepRollbackDeinstallationSecurity::undo() {
28   std::string error_message;
29   if (!RegisterSecurityContextForManifest(context_, &error_message)) {
30     LOG(ERROR) << "Failure on re-installing security context for app "
31                << context_->pkgid.get();
32     if (!error_message.empty()) {
33       LOG(ERROR) << "error_message: " << error_message;
34     }
35     return Status::SECURITY_ERROR;
36   }
37   if (!RegisterSecurityContextForPath(context_->pkgid.get(),
38       context_->pkg_type.get(), context_->GetPkgPath(), context_->uid.get(),
39       context_->is_readonly_package.get(), &error_message)) {
40     if (!error_message.empty()) {
41       LOG(ERROR) << "error_message: " << error_message;
42       on_error_->on_error(Status::SECURITY_ERROR, error_message);
43     }
44     return Status::SECURITY_ERROR;
45   }
46   LOG(DEBUG) << "Security context installed";
47   return Status::OK;
48 }
49
50 }  // namespace security
51 }  // namespace common_installer