Fix smack labeling for lib rpk
[platform/core/appfw/app-installers.git] / src / common / step / security / step_recover_security.cc
index 84c6114..a7a62fc 100644 (file)
@@ -25,10 +25,16 @@ bool StepRecoverSecurity::Check(bool is_update) {
 Step::Status StepRecoverSecurity::RecoveryNew() {
   if (!Check(false))
     return Status::OK;
+  recovery::RecoveryFile* recovery_file =
+      context_->recovery_info.get().recovery_file.get();
+  if (!recovery_file->security_operation_done()) {
+    LOG(DEBUG) << "security_operation_done false skip recover security";
+    return Status::OK;
+  }
   std::string error_message;
   if (!context_->manifest_data.get()) {
     if (!UnregisterSecurityContextForPkgId(context_->pkgid.get(),
-        context_->uid.get(), &error_message, true)) {
+        context_->pkg_type.get(), context_->uid.get(), &error_message, true)) {
       LOG(ERROR) << "Unsuccessful install";
       if (!error_message.empty()) {
         LOG(ERROR) << "error_message: " << error_message;
@@ -37,7 +43,7 @@ Step::Status StepRecoverSecurity::RecoveryNew() {
       return Status::RECOVERY_ERROR;
     }
   } else if (!UnregisterSecurityContextForManifest(
-      context_->pkgid.get(), context_->uid.get(),
+      context_->pkgid.get(), context_->pkg_type.get(), context_->uid.get(),
       context_->manifest_data.get(), &error_message)) {
     LOG(ERROR) << "Unsuccessful install";
     if (!error_message.empty()) {
@@ -54,11 +60,14 @@ Step::Status StepRecoverSecurity::RecoveryUpdate() {
     LOG(ERROR) << "Invalid parameters";
     return Status::INVALID_VALUE;
   }
+  recovery::RecoveryFile* recovery_file =
+      context_->recovery_info.get().recovery_file.get();
+  if (!recovery_file->security_operation_done()) {
+    LOG(DEBUG) << "security_operation_done false skip recover security";
+    return Status::OK;
+  }
   std::string error_message;
-  if (!RegisterSecurityContextForManifest(
-      context_->pkgid.get(), context_->GetPkgPath(), context_->uid.get(),
-      &context_->certificate_info.get(), context_->manifest_data.get(),
-      context_->cross_app_rules.get(), &error_message)) {
+  if (!RegisterSecurityContextForManifest(context_, &error_message)) {
     LOG(ERROR) << "Unsuccessful update";
     if (!error_message.empty()) {
       LOG(ERROR) << "error_message: " << error_message;
@@ -66,12 +75,16 @@ Step::Status StepRecoverSecurity::RecoveryUpdate() {
     }
     return Status::RECOVERY_ERROR;
   }
-  if (!RegisterSecurityContextForPath(
-      context_->pkgid.get(), context_->GetPkgPath(), context_->uid.get(),
+
+  if (!HasOwnerRwOtherRoPaths(context_->GetPkgPath()))
+    return Status::OK;
+
+  if (!RegisterSecurityContextForPath(context_->pkgid.get(),
+      context_->pkg_type.get(), context_->GetPkgPath(), context_->uid.get(),
       context_->is_readonly_package.get(), &error_message)) {
     if (!error_message.empty()) {
       LOG(ERROR) << "error_message: " << error_message;
-      on_error(Status::SECURITY_ERROR, error_message);
+      on_error(Status::RECOVERY_ERROR, error_message);
     }
     return Status::RECOVERY_ERROR;
   }
@@ -83,11 +96,14 @@ Step::Status StepRecoverSecurity::RecoveryReadonlyUpdateInstall() {
     LOG(ERROR) << "Invalid parameters";
     return Status::INVALID_VALUE;
   }
+  recovery::RecoveryFile* recovery_file =
+      context_->recovery_info.get().recovery_file.get();
+  if (!recovery_file->security_operation_done()) {
+    LOG(DEBUG) << "security_operation_done false skip recover security";
+    return Status::OK;
+  }
   std::string error_message;
-  if (!RegisterSecurityContextForManifest(
-      context_->pkgid.get(), context_->GetPkgPath(), context_->uid.get(),
-      &context_->certificate_info.get(), context_->manifest_data.get(),
-      context_->cross_app_rules.get(), &error_message)) {
+  if (!RegisterSecurityContextForManifest(context_, &error_message)) {
     LOG(ERROR) << "Unsuccessful update";
     if (!error_message.empty()) {
       LOG(ERROR) << "error_message: " << error_message;