Generic solution for onlycap issues
[platform/core/test/security-tests.git] / src / ckm-integration / process-settings / change-smack.cpp
index f56c506..f83aec4 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *  Copyright (c) 2015 - 2019 Samsung Electronics Co., Ltd All Rights Reserved
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@
 /*
  * @file       change-smack.cpp
  * @author     Bartlomiej Grzelewski (b.grzelewski@samsung.com)
+ * @author     Krzysztof Jackiewicz (k.jackiewicz@samsung.com)
  * @version    1.0
  */
 #include <sys/smack.h>
@@ -23,6 +24,7 @@
 #include <tests_common.h>
 
 #include <process-settings/change-smack.h>
+#include <scoped_process_label.h>
 
 namespace ProcessSettings {
 
@@ -31,22 +33,11 @@ ChangeSmack::ChangeSmack(const Policy &policy)
 {}
 
 void ChangeSmack::Apply() {
-    char *my_label = nullptr;
-
-    RUNNER_ASSERT(-1 != smack_new_label_from_self(&my_label));
-
-    if (my_label)
-        m_originalLabel = my_label;
-
-    free(my_label);
-
-    RUNNER_ASSERT_MSG(0 == smack_set_label_for_self(m_policy.GetSmackLabel().c_str()),
-        "Error in smack_set_label_for_self(" << m_policy.GetSmackLabel() << ")");
+    m_processLabel.reset(new ScopedProcessLabel(m_policy.GetSmackLabel()));
 }
 
 void ChangeSmack::Revoke() {
-    RUNNER_ASSERT_MSG(0 == smack_set_label_for_self(m_originalLabel.c_str()),
-        "Error in smack_set_label_for_self(" << m_originalLabel << ")");
+    m_processLabel.reset();
 }
 
 ChangeSmack::~ChangeSmack() {}