Merge branch 'tizen' into yaca 74/249774/1
authorDariusz Michaluk <d.michaluk@samsung.com>
Wed, 16 Dec 2020 12:07:27 +0000 (13:07 +0100)
committerDariusz Michaluk <d.michaluk@samsung.com>
Wed, 16 Dec 2020 12:07:27 +0000 (13:07 +0100)
Change-Id: I9854e1e1e8d29d204041ccd831b032b87ec5173c

35 files changed:
CMakeLists.txt
README
packaging/security-tests.manifest
packaging/security-tests.spec
src/CMakeLists.txt
src/ckm/privileged/CMakeLists.txt
src/ckm/privileged/access_provider2.cpp [deleted file]
src/ckm/privileged/access_provider2.h [deleted file]
src/ckm/privileged/async-api.cpp
src/ckm/privileged/capi-access_control.cpp
src/ckm/privileged/initial-values.cpp
src/ckm/privileged/main.cpp
src/ckm/privileged/scoped-app-context.cpp [new file with mode: 0644]
src/ckm/privileged/scoped-app-context.h [new file with mode: 0644]
src/ckm/privileged/system-db.cpp
src/common/CMakeLists.txt
src/common/access_provider.cpp [deleted file]
src/common/app_context.cpp [new file with mode: 0644]
src/common/app_context.h [moved from src/common/access_provider.h with 51% similarity]
src/common/scoped_process_label.cpp
src/common/scoped_process_label.h
src/common/smack_access.cpp
src/common/smack_access.h
src/cynara-tests/test_cases_helpers.cpp
src/libsmack-tests/CMakeLists.txt [deleted file]
src/libsmack-tests/libsmack-test.cpp [deleted file]
src/libsmack-tests/test_cases.cpp [deleted file]
src/libsmack-tests/test_smack_rules [deleted file]
src/libsmack-tests/test_smack_rules2 [deleted file]
src/libsmack-tests/test_smack_rules3 [deleted file]
src/libsmack-tests/test_smack_rules4 [deleted file]
src/libsmack-tests/test_smack_rules_full [deleted file]
src/security-manager-tests/test_cases_credentials.cpp
src/security-tests-all.sh
src/security-tests.sh

index 26b21d0..e941f15 100644 (file)
@@ -35,7 +35,7 @@ INCLUDE(FindPkgConfig)
 ############################# compiler flags ##################################
 
 SET(CMAKE_C_FLAGS              "-g")
-SET(CMAKE_CXX_FLAGS            "-g -std=c++14")
+SET(CMAKE_CXX_FLAGS            "-g -std=c++17")
 SET(CMAKE_C_FLAGS_PROFILING    "-O0 -pg")
 SET(CMAKE_CXX_FLAGS_PROFILING  "-O0 -pg")
 SET(CMAKE_C_FLAGS_DEBUG        "-O0 -ggdb")
diff --git a/README b/README
index a036712..fe33548 100644 (file)
--- a/README
+++ b/README
@@ -9,8 +9,6 @@ security-tests is repository for testing packages from domain Security.
 The security-tests repository is designed for testing packages mentioned below
 with binaries provided for testing them:
 
-libsmack
-  libsmack-test
 security-manager
   security-manager-tests
 cynara
index ea004f1..9b87770 100644 (file)
@@ -2,7 +2,6 @@
     <assign>
         <filesystem path="/usr/bin/test-performance-check.sh" exec_label="_" />
 
-        <filesystem path="/usr/bin/libsmack-test" exec_label="_" />
         <filesystem path="/usr/bin/security-manager-tests" exec_label="System::Privileged" />
         <filesystem path="/usr/bin/cynara-tests" exec_label="_" />
         <filesystem path="/usr/bin/ckm-tests" exec_label="User" />
index d7d6de7..249a34e 100644 (file)
@@ -86,7 +86,6 @@ id -u  security_test_user 1>/dev/null 2>&1 || \
 
 %install
 %make_install
-ln -sf /etc/smack/test_smack_rules %{buildroot}/etc/smack/test_smack_rules_lnk
 cp -a %{SOURCE1} %{buildroot}%{_datadir}/
 
 %post
@@ -108,14 +107,7 @@ echo "security-tests postinst done ..."
 
 /etc/dbus-1/system.d/security-tests.conf
 
-/usr/bin/libsmack-test
-/etc/smack/test_smack_rules_full
-/etc/smack/test_smack_rules2
-/etc/smack/test_smack_rules3
-/etc/smack/test_smack_rules4
 /usr/bin/security-manager-tests
-/etc/smack/test_smack_rules
-/etc/smack/test_smack_rules_lnk
 %{TZ_SYS_RW_APP}*
 %attr(755, security_test_user,users) %{TZ_SYS_HOME}/security_test_user/apps_rw/*
 /usr/bin/cynara-test
index aadbe67..736b6e8 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (c) 2011-2017 Samsung Electronics Co., Ltd All Rights Reserved
+# Copyright (c) 2011-2020 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.
@@ -87,7 +87,6 @@ INSTALL(FILES
 
 IF(BUILD_CKM OR BUILD_SM OR BUILD_CYNARA OR BUILD_WEB)
     ADD_SUBDIRECTORY(common)
-    ADD_SUBDIRECTORY(libsmack-tests)
 ENDIF(BUILD_CKM OR BUILD_SM OR BUILD_CYNARA OR BUILD_WEB)
 
 IF(BUILD_CKM)
index 705562c..ee8ce0b 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (c) 2013-2019 Samsung Electronics Co., Ltd All Rights Reserved
+# Copyright (c) 2013-2020 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.
@@ -83,12 +83,12 @@ PKG_CHECK_MODULES(CKM_DEP
 )
 
 SET(CKM_SOURCES
-    access_provider2.cpp
     async-api.cpp
     capi-access_control.cpp
     ckm-privileged-common.cpp
     initial-values.cpp
     main.cpp
+    scoped-app-context.cpp
     system-db.cpp
 )
 
diff --git a/src/ckm/privileged/access_provider2.cpp b/src/ckm/privileged/access_provider2.cpp
deleted file mode 100644 (file)
index 2d98ace..0000000
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- * Copyright (c) 2013 - 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.
- *    You may obtain a copy of the License at
- *
- *        http://www.apache.org/licenses/LICENSE-2.0
- *
- *    Unless required by applicable law or agreed to in writing, software
- *    distributed under the License is distributed on an "AS IS" BASIS,
- *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *    See the License for the specific language governing permissions and
- *    limitations under the License.
- */
-/*
- * @file        access_provider.cpp
- * @author      Bartlomiej Grzelewski (b.grzelewski@samsung.com)
- * @author      Krzysztof Jackiewicz (k.jackiewicz@samsung.com)
- * @version     1.0
- * @brief       Common functions and macros used in security-tests package.
- */
-#include <sys/types.h>
-#include <unistd.h>
-#include <sys/smack.h>
-
-#include <access_provider2.h>
-#include <tests_common.h>
-#include <ckm-common.h>
-#include <scoped_process_label.h>
-
-namespace {
-
-std::string toSmackLabel(const std::string &ownerId) {
-    if (ownerId.empty())
-        return ownerId;
-
-    if (ownerId[0] == '/') {
-        return ownerId.substr(1, std::string::npos);
-    }
-
-    return SMACK_USER_APP_PREFIX + ownerId;
-}
-
-} // anonymous namespace
-
-AccessProvider::AccessProvider(const std::string &ownerId)
-  : m_mySubject(toSmackLabel(ownerId))
-  , m_inSwitchContext(false)
-{
-    RUNNER_ASSERT_MSG(m_mySubject.size() > 0, "No smack label provided to AccessProvider!");
-    allowJournaldLogs();
-}
-
-AccessProvider::AccessProvider(const std::string &ownerId, int uid, int gid)
-  : m_mySubject(toSmackLabel(ownerId))
-  , m_inSwitchContext(false)
-{
-    RUNNER_ASSERT_MSG(m_mySubject.size() > 0, "No smack label provided to AccessProvider!");
-    allowJournaldLogs();
-    applyAndSwithToUser(uid, gid);
-}
-
-AccessProvider::~AccessProvider()
-{
-
-}
-
-void AccessProvider::allowAPI(const std::string &api, const std::string &rule) {
-    m_smackAccess.add(m_mySubject, api, rule);
-}
-
-void AccessProvider::apply() {
-    // This should be done by security-manager
-    m_smackAccess.add("System", m_mySubject, "w");
-    m_smackAccess.add(m_mySubject, "System", "w");
-    m_smackAccess.apply();
-}
-
-void AccessProvider::applyAndSwithToUser(int uid, int gid)
-{
-    RUNNER_ASSERT_MSG(m_inSwitchContext == false, "already switched context");
-
-    RUNNER_ASSERT_MSG(0 == smack_revoke_subject(m_mySubject.c_str()),
-        "Error in smack_revoke_subject(" << m_mySubject << ")");
-    apply();
-
-    m_processLabel.reset(new ScopedProcessLabel(m_mySubject));
-
-    m_origUid = getuid();
-    m_origGid = getgid();
-    RUNNER_ASSERT_MSG(0 == setegid(gid),
-        "Error in setgid.");
-    RUNNER_ASSERT_MSG(0 == seteuid(uid),
-        "Error in setuid.");
-    m_inSwitchContext = true;
-}
-
-void AccessProvider::allowJournaldLogs() {
-    allowAPI("System::Run","wx"); // necessary for logging with journald
-}
-
-ScopedAccessProvider::~ScopedAccessProvider()
-{
-    if(m_inSwitchContext == true)
-    {
-        RUNNER_ASSERT_MSG(0 == setegid(m_origGid), "Error in setgid.");
-        RUNNER_ASSERT_MSG(0 == seteuid(m_origUid), "Error in setuid.");
-        RUNNER_ASSERT_MSG(0 == smack_revoke_subject(m_mySubject.c_str()),
-            "Error in smack_revoke_subject(" << m_mySubject << ")");
-        m_processLabel.reset();
-        m_inSwitchContext = false;
-    }
-}
diff --git a/src/ckm/privileged/access_provider2.h b/src/ckm/privileged/access_provider2.h
deleted file mode 100644 (file)
index d2e19b5..0000000
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Copyright (c) 2013 - 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.
- *    You may obtain a copy of the License at
- *
- *        http://www.apache.org/licenses/LICENSE-2.0
- *
- *    Unless required by applicable law or agreed to in writing, software
- *    distributed under the License is distributed on an "AS IS" BASIS,
- *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *    See the License for the specific language governing permissions and
- *    limitations under the License.
- */
-/*
- * @file        access_provider2.h
- * @author      Bartlomiej Grzelewski (b.grzelewski@samsung.com)
- * @version     1.0
- * @brief       Common functions and macros used in security-tests package.
- */
-#ifndef _ACCESS_FOR_DUMMIES_H_
-#define _ACCESS_FOR_DUMMIES_H_
-
-#include <string>
-#include <memory>
-
-#include <smack_access.h>
-
-class ScopedProcessLabel;
-
-class AccessProvider {
-public:
-    explicit AccessProvider(const std::string &ownerId);
-    AccessProvider(const std::string &ownerId, int uid, int gid);
-    virtual ~AccessProvider();
-
-    AccessProvider(const AccessProvider &second) = delete;
-    AccessProvider& operator=(const AccessProvider &second) = delete;
-
-    void allowAPI(const std::string &api, const std::string &rules);
-    void apply();
-    void applyAndSwithToUser(int uid, int gid);
-
-private:
-    void allowJournaldLogs();
-
-    SmackAccess m_smackAccess;
-protected:
-    std::string m_mySubject;
-    uid_t m_origUid;
-    gid_t m_origGid;
-    std::unique_ptr<ScopedProcessLabel> m_processLabel;
-    bool m_inSwitchContext;
-};
-
-class ScopedAccessProvider : public AccessProvider {
-public:
-    explicit ScopedAccessProvider(const std::string &mySubject)
-        : AccessProvider(mySubject) {}
-    ScopedAccessProvider(const std::string &mySubject, int uid, int gid)
-        : AccessProvider(mySubject, uid, gid) {}
-    virtual ~ScopedAccessProvider();
-};
-
-#endif // _ACCESS_FOR_DUMMIES_H_
index 69f090a..371c488 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright (c) 2000 - 2019 Samsung Electronics Co., Ltd All Rights Reserved
+ *  Copyright (c) 2000 - 2020 Samsung Electronics Co., Ltd All Rights Reserved
  *
  *  Contact: Bumjin Im <bj.im@samsung.com>
  *
@@ -40,7 +40,7 @@
 #include <tests_common.h>
 #include <test-certs.h>
 #include <ckm-common.h>
-#include <access_provider2.h>
+#include <scoped-app-context.h>
 #include <random>
 
 using namespace CKM;
@@ -390,14 +390,14 @@ public:
     void init(const std::string & str) {
         RemoveDataEnv<APP_UID>::init(str);
         unlock_user_data(APP_UID, TEST_PASS);
-        m_ap.reset(new ScopedAccessProvider(TEST_LABEL, APP_UID, APP_GID));
+        m_ctx.reset(new ScopedAppContext(TEST_LABEL, APP_UID, APP_GID));
     }
     void finish() {
-        m_ap.reset();
+        m_ctx.reset();
         // lock is performed by remove_user_data() in RemoveDataEnv
         RemoveDataEnv<APP_UID>::finish();
     }
-    std::unique_ptr<ScopedAccessProvider> m_ap;
+    std::unique_ptr<ScopedAppContext> m_ctx;
 };
 
 } // namespace anonymous
@@ -421,7 +421,7 @@ RUNNER_TEST(TA1820_allow_access, RemoveDataEnv<APP_UID>)
     std::string alias2 = aliasWithLabel(TEST_LABEL, "alias-2");
     std::string alias3 = aliasWithLabel(TEST_LABEL, "alias-3");
     {
-        ScopedAccessProvider ap(TEST_LABEL, APP_UID, APP_GID);
+        ScopedAppContext ctx(TEST_LABEL, APP_UID, APP_GID);
         save_data(alias1.c_str(), TEST_DATA);
         save_data(alias2.c_str(), TEST_DATA);
         save_data(alias3.c_str(), TEST_DATA);
@@ -437,7 +437,7 @@ RUNNER_TEST(TA1820_allow_access, RemoveDataEnv<APP_UID>)
     }
 
     {
-        ScopedAccessProvider ap(TEST_LABEL_2, APP_UID, APP_GID);
+        ScopedAppContext ctx(TEST_LABEL_2, APP_UID, APP_GID);
 
         test_negative(&ManagerAsync::getData, CKM_API_ERROR_DB_ALIAS_UNKNOWN, alias1, "");
         test_negative(&ManagerAsync::removeAlias, CKM_API_ERROR_DB_ALIAS_UNKNOWN, alias1);
@@ -469,7 +469,7 @@ RUNNER_TEST(TA1920_deny_access, RemoveDataEnv<APP_UID>)
     // prepare: add data
     std::string alias1 = aliasWithLabel(TEST_LABEL, "alias-1");
     {
-        ScopedAccessProvider ap(TEST_LABEL, APP_UID, APP_GID);
+        ScopedAppContext ctx(TEST_LABEL, APP_UID, APP_GID);
         save_data(alias1.c_str(), TEST_DATA);
 
         test_positive(&ManagerAsync::setPermission,
@@ -483,7 +483,7 @@ RUNNER_TEST(TA1920_deny_access, RemoveDataEnv<APP_UID>)
     }
 
     {
-        ScopedAccessProvider ap(TEST_LABEL_2, APP_UID, APP_GID);
+        ScopedAppContext ctx(TEST_LABEL_2, APP_UID, APP_GID);
 
         test_negative(&ManagerAsync::getData, CKM_API_ERROR_DB_ALIAS_UNKNOWN, alias1, "");
         test_negative(&ManagerAsync::removeAlias, CKM_API_ERROR_DB_ALIAS_UNKNOWN, alias1);
index db28b1c..351c0b2 100644 (file)
@@ -6,7 +6,7 @@
 
 #include <tests_common.h>
 #include <ckm-common.h>
-#include <access_provider2.h>
+#include <scoped-app-context.h>
 
 #include <ckmc/ckmc-manager.h>
 #include <ckmc/ckmc-control.h>
@@ -96,7 +96,7 @@ RUNNER_TEST(T3000_init)
 // invalid arguments check
 RUNNER_TEST(T3001_manager_allow_access_invalid)
 {
-    ScopedAccessProvider ap(APP_LABEL_1, APP_1, GROUP_1);
+    ScopedAppContext ctx(APP_LABEL_1, APP_1, GROUP_1);
 
     RUNNER_ASSERT(
             CKMC_ERROR_INVALID_PARAMETER == ckmc_set_permission(NULL, "accessor", CKMC_PERMISSION_READ));
@@ -107,7 +107,7 @@ RUNNER_TEST(T3001_manager_allow_access_invalid)
 // invalid arguments check
 RUNNER_TEST(T3002_manager_deny_access_invalid)
 {
-    ScopedAccessProvider ap(APP_LABEL_1, APP_1, GROUP_1);
+    ScopedAppContext ctx(APP_LABEL_1, APP_1, GROUP_1);
 
     RUNNER_ASSERT(CKMC_ERROR_INVALID_PARAMETER == ckmc_set_permission(NULL, "accessor", CKMC_PERMISSION_NONE));
     RUNNER_ASSERT(CKMC_ERROR_INVALID_PARAMETER == ckmc_set_permission("alias", NULL, CKMC_PERMISSION_NONE));
@@ -116,7 +116,7 @@ RUNNER_TEST(T3002_manager_deny_access_invalid)
 // tries to allow access for non existing alias
 RUNNER_CHILD_TEST(T3003_manager_allow_access_non_existing)
 {
-    ScopedAccessProvider ap(APP_LABEL_1, APP_1, GROUP_1);
+    ScopedAppContext ctx(APP_LABEL_1, APP_1, GROUP_1);
 
     int ret = ckmc_set_permission(NO_ALIAS, "label", CKMC_PERMISSION_READ);
     RUNNER_ASSERT_MSG(CKMC_ERROR_DB_ALIAS_UNKNOWN == ret,
@@ -126,7 +126,7 @@ RUNNER_CHILD_TEST(T3003_manager_allow_access_non_existing)
 // tries to deny access for non existing alias
 RUNNER_CHILD_TEST(T3004_manager_deny_access_non_existing)
 {
-    ScopedAccessProvider ap(APP_LABEL_1, APP_1, GROUP_1);
+    ScopedAppContext ctx(APP_LABEL_1, APP_1, GROUP_1);
 
     int ret = ckmc_set_permission(NO_ALIAS, "label", CKMC_PERMISSION_NONE);
     RUNNER_ASSERT_MSG(CKMC_ERROR_DB_ALIAS_UNKNOWN == ret,
@@ -136,7 +136,7 @@ RUNNER_CHILD_TEST(T3004_manager_deny_access_non_existing)
 // tries to deny access that does not exist in database
 RUNNER_CHILD_TEST(T3005_manager_deny_access_non_existing_access)
 {
-    ScopedAccessProvider ap(APP_LABEL_1, APP_1, GROUP_1);
+    ScopedAppContext ctx(APP_LABEL_1, APP_1, GROUP_1);
 
     ScopedSaveData ssd(TEST_ALIAS, TEST_DATA);
 
@@ -149,7 +149,7 @@ RUNNER_CHILD_TEST(T3005_manager_deny_access_non_existing_access)
 // tries to allow access to application own data
 RUNNER_CHILD_TEST(T3006_manager_allow_access_to_myself)
 {
-    ScopedAccessProvider ap(APP_LABEL_1, APP_1, GROUP_1);
+    ScopedAppContext ctx(APP_LABEL_1, APP_1, GROUP_1);
 
     ScopedSaveData ssd(TEST_ALIAS, TEST_DATA);
 
@@ -162,7 +162,7 @@ RUNNER_CHILD_TEST(T3006_manager_allow_access_to_myself)
 // verifies that alias can not contain forbidden characters
 RUNNER_CHILD_TEST(T3007_manager_check_alias_valid)
 {
-    ScopedAccessProvider ap(APP_LABEL_1, APP_1, GROUP_1);
+    ScopedAppContext ctx(APP_LABEL_1, APP_1, GROUP_1);
 
     ScopedSaveData ssd(TEST_ALIAS, TEST_DATA);
 
@@ -177,7 +177,7 @@ RUNNER_CHILD_TEST(T3007_manager_check_alias_valid)
 // verifies that label can not contain forbidden characters
 RUNNER_CHILD_TEST(T3008_manager_check_label_valid)
 {
-    ScopedAccessProvider ap(APP_LABEL_1, APP_1, GROUP_1);
+    ScopedAppContext ctx(APP_LABEL_1, APP_1, GROUP_1);
 
     ScopedSaveData ssd(TEST_ALIAS, TEST_DATA);
 
@@ -210,13 +210,13 @@ RUNNER_TEST(T3020_manager_access_not_allowed, RemoveDataEnv<APP_1>)
 {
     // prepare: add data
     {
-        ScopedAccessProvider ap(APP_LABEL_1, APP_1, GROUP_1);
+        ScopedAppContext ctx(APP_LABEL_1, APP_1, GROUP_1);
         save_data(TEST_ALIAS, TEST_DATA);
     }
 
     // test accessibility from another label
     {
-        ScopedAccessProvider ap(APP_LABEL_2, APP_1, GROUP_1);
+        ScopedAppContext ctx(APP_LABEL_2, APP_1, GROUP_1);
 
         std::string TEST_ALIAS_adr = aliasWithLabel(APP_LABEL_1, TEST_ALIAS);
         check_read_not_visible(TEST_ALIAS_adr.c_str());
@@ -229,14 +229,14 @@ RUNNER_TEST(T3021_manager_access_allowed, RemoveDataEnv<APP_1>)
 {
     // prepare: add data
     {
-        ScopedAccessProvider ap(APP_LABEL_1, APP_1, GROUP_1);
+        ScopedAppContext ctx(APP_LABEL_1, APP_1, GROUP_1);
         save_data(TEST_ALIAS, TEST_DATA);
         allow_access(TEST_ALIAS, APP_LABEL_2, CKMC_PERMISSION_READ);
     }
 
     // test accessibility from another label
     {
-        ScopedAccessProvider ap(APP_LABEL_2, APP_1, GROUP_1);
+        ScopedAppContext ctx(APP_LABEL_2, APP_1, GROUP_1);
         check_read_allowed(aliasWithLabel(APP_LABEL_1, TEST_ALIAS).c_str(), TEST_DATA);
     }
 }
@@ -246,14 +246,14 @@ RUNNER_TEST(T3022_manager_access_allowed_with_remove, RemoveDataEnv<APP_1>)
 {
     // prepare: add data
     {
-        ScopedAccessProvider ap(APP_LABEL_1, APP_1, GROUP_1);
+        ScopedAppContext ctx(APP_LABEL_1, APP_1, GROUP_1);
         save_data(TEST_ALIAS, TEST_DATA);
         allow_access(TEST_ALIAS, APP_LABEL_2, CKMC_PERMISSION_READ | CKMC_PERMISSION_REMOVE);
     }
 
     // test accessibility from another label
     {
-        ScopedAccessProvider ap(APP_LABEL_2, APP_1, GROUP_1);
+        ScopedAppContext ctx(APP_LABEL_2, APP_1, GROUP_1);
         check_read_allowed(aliasWithLabel(APP_LABEL_1, TEST_ALIAS).c_str(), TEST_DATA);
     }
 }
@@ -263,14 +263,14 @@ RUNNER_TEST(T3023_manager_access_allowed_remove_denied, RemoveDataEnv<APP_1>)
 {
     // prepare: add data
     {
-        ScopedAccessProvider ap(APP_LABEL_1, APP_1, GROUP_1);
+        ScopedAppContext ctx(APP_LABEL_1, APP_1, GROUP_1);
         save_data(TEST_ALIAS, TEST_DATA);
         allow_access(TEST_ALIAS, APP_LABEL_2, CKMC_PERMISSION_READ);
     }
 
     // test accessibility from another label
     {
-        ScopedAccessProvider ap(APP_LABEL_2, APP_1, GROUP_1);
+        ScopedAppContext ctx(APP_LABEL_2, APP_1, GROUP_1);
         std::string TEST_ALIAS_adr = aliasWithLabel(APP_LABEL_1, TEST_ALIAS);
         check_remove_denied(TEST_ALIAS_adr.c_str());
         check_read_allowed(TEST_ALIAS_adr.c_str(), TEST_DATA);
@@ -282,14 +282,14 @@ RUNNER_TEST(T3025_manager_remove_allowed, RemoveDataEnv<APP_1>)
 {
     // prepare: add data
     {
-        ScopedAccessProvider ap(APP_LABEL_1, APP_1, GROUP_1);
+        ScopedAppContext ctx(APP_LABEL_1, APP_1, GROUP_1);
         save_data(TEST_ALIAS, TEST_DATA);
         allow_access(TEST_ALIAS, APP_LABEL_2, CKMC_PERMISSION_READ | CKMC_PERMISSION_REMOVE);
     }
 
     // test accessibility from another label
     {
-        ScopedAccessProvider ap(APP_LABEL_2, APP_1, GROUP_1);
+        ScopedAppContext ctx(APP_LABEL_2, APP_1, GROUP_1);
         check_remove_allowed(aliasWithLabel(APP_LABEL_1, TEST_ALIAS).c_str());
     }
 }
@@ -300,7 +300,7 @@ RUNNER_TEST(T3026_manager_double_allow, RemoveDataEnv<APP_1>)
 {
     // prepare: add data
     {
-        ScopedAccessProvider ap(APP_LABEL_1, APP_1, GROUP_1);
+        ScopedAppContext ctx(APP_LABEL_1, APP_1, GROUP_1);
         save_data(TEST_ALIAS, TEST_DATA);
 
         // access should be overwritten
@@ -310,7 +310,7 @@ RUNNER_TEST(T3026_manager_double_allow, RemoveDataEnv<APP_1>)
 
     // test accessibility from another label
     {
-        ScopedAccessProvider ap(APP_LABEL_2, APP_1, GROUP_1);
+        ScopedAppContext ctx(APP_LABEL_2, APP_1, GROUP_1);
 
         std::string TEST_ALIAS_adr = aliasWithLabel(APP_LABEL_1, TEST_ALIAS);
         check_remove_denied(TEST_ALIAS_adr.c_str());
@@ -324,7 +324,7 @@ RUNNER_TEST(T3027_manager_allow_deny, RemoveDataEnv<APP_1>)
     // prepare: add data
     std::string TEST_ALIAS_adr = aliasWithLabel(APP_LABEL_1, TEST_ALIAS);
     {
-        ScopedAccessProvider ap(APP_LABEL_1, APP_1, GROUP_1);
+        ScopedAppContext ctx(APP_LABEL_1, APP_1, GROUP_1);
         save_data(TEST_ALIAS, TEST_DATA);
 
         allow_access(TEST_ALIAS, APP_LABEL_2, CKMC_PERMISSION_READ);
@@ -332,7 +332,7 @@ RUNNER_TEST(T3027_manager_allow_deny, RemoveDataEnv<APP_1>)
 
     // test accessibility from another label
     {
-        ScopedAccessProvider ap(APP_LABEL_2, APP_1, GROUP_1);
+        ScopedAppContext ctx(APP_LABEL_2, APP_1, GROUP_1);
 
         check_remove_denied(TEST_ALIAS_adr.c_str());
         check_read_allowed(TEST_ALIAS_adr.c_str(), TEST_DATA);
@@ -340,14 +340,14 @@ RUNNER_TEST(T3027_manager_allow_deny, RemoveDataEnv<APP_1>)
 
     // remove permission
     {
-        ScopedAccessProvider ap(APP_LABEL_1, APP_1, GROUP_1);
+        ScopedAppContext ctx(APP_LABEL_1, APP_1, GROUP_1);
 
         deny_access(TEST_ALIAS, APP_LABEL_2);
     }
 
     // test accessibility from another label
     {
-        ScopedAccessProvider ap(APP_LABEL_2, APP_1, GROUP_1);
+        ScopedAppContext ctx(APP_LABEL_2, APP_1, GROUP_1);
 
         check_remove_not_visible(TEST_ALIAS_adr.c_str());
         check_read_not_visible(TEST_ALIAS_adr.c_str());
@@ -359,7 +359,7 @@ RUNNER_TEST(T3028_manager_access_by_label, RemoveDataEnv<APP_1>)
     // prepare: add data
     const char *additional_data = "label-2-data";
     {
-        ScopedAccessProvider ap(APP_LABEL_1, APP_1, GROUP_1);
+        ScopedAppContext ctx(APP_LABEL_1, APP_1, GROUP_1);
         save_data(TEST_ALIAS, TEST_DATA);
 
         allow_access(TEST_ALIAS, APP_LABEL_2, CKMC_PERMISSION_READ);
@@ -367,7 +367,7 @@ RUNNER_TEST(T3028_manager_access_by_label, RemoveDataEnv<APP_1>)
 
     // add data as app 2
     {
-        ScopedAccessProvider ap(APP_LABEL_2, APP_1, GROUP_1);
+        ScopedAppContext ctx(APP_LABEL_2, APP_1, GROUP_1);
         save_data(TEST_ALIAS, additional_data);
 
         allow_access(TEST_ALIAS, APP_LABEL_1, CKMC_PERMISSION_READ);
@@ -378,7 +378,7 @@ RUNNER_TEST(T3028_manager_access_by_label, RemoveDataEnv<APP_1>)
 
     // test accessibility to app 2 from app 1
     {
-        ScopedAccessProvider ap(APP_LABEL_1, APP_1, GROUP_1);
+        ScopedAppContext ctx(APP_LABEL_1, APP_1, GROUP_1);
 
         // test if can access label2 alias from label1 domain - should succeed
         check_read_allowed(aliasWithLabel(APP_LABEL_2, TEST_ALIAS).c_str(), additional_data);
@@ -390,7 +390,7 @@ RUNNER_TEST(T3029_manager_access_modification_by_foreign_label, RemoveDataEnv<AP
 {
     // prepare: add data
     {
-        ScopedAccessProvider ap(APP_LABEL_1, APP_1, GROUP_1);
+        ScopedAppContext ctx(APP_LABEL_1, APP_1, GROUP_1);
         save_data(TEST_ALIAS, TEST_DATA);
 
         allow_access(TEST_ALIAS, APP_LABEL_3, CKMC_PERMISSION_READ | CKMC_PERMISSION_REMOVE);
@@ -398,7 +398,7 @@ RUNNER_TEST(T3029_manager_access_modification_by_foreign_label, RemoveDataEnv<AP
 
     // test accessibility from another label
     {
-        ScopedAccessProvider ap(APP_LABEL_2, APP_1, GROUP_1);
+        ScopedAppContext ctx(APP_LABEL_2, APP_1, GROUP_1);
 
         allow_access_negative(aliasWithLabel(APP_LABEL_1, TEST_ALIAS).c_str(), APP_LABEL_4, CKMC_PERMISSION_READ | CKMC_PERMISSION_REMOVE, CKMC_ERROR_PERMISSION_DENIED);
         deny_access_negative (aliasWithLabel(APP_LABEL_1, TEST_ALIAS).c_str(), APP_LABEL_4, CKMC_ERROR_PERMISSION_DENIED);
@@ -411,7 +411,7 @@ RUNNER_TEST(T3030_manager_get_all_aliases, RemoveDataEnv<APP_1>)
     // prepare: add data
     size_t count;
     {
-        ScopedAccessProvider ap(APP_LABEL_1, APP_1, GROUP_1);
+        ScopedAppContext ctx(APP_LABEL_1, APP_1, GROUP_1);
         save_data(TEST_ALIAS, TEST_DATA);
         save_data(TEST_ALIAS2, TEST_DATA);
 
@@ -421,7 +421,7 @@ RUNNER_TEST(T3030_manager_get_all_aliases, RemoveDataEnv<APP_1>)
 
     // test accessibility from another label
     {
-        ScopedAccessProvider ap(APP_LABEL_2, APP_1, GROUP_1);
+        ScopedAppContext ctx(APP_LABEL_2, APP_1, GROUP_1);
 
         // check that app can access other aliases when it has permission
         check_alias_count(count - 1);
@@ -434,13 +434,13 @@ RUNNER_TEST(T3030_manager_get_all_aliases, RemoveDataEnv<APP_1>)
 
     // remove permission
     {
-        ScopedAccessProvider ap(APP_LABEL_1, APP_1, GROUP_1);
+        ScopedAppContext ctx(APP_LABEL_1, APP_1, GROUP_1);
         deny_access(TEST_ALIAS, APP_LABEL_2);
     }
 
     // test accessibility from another label
     {
-        ScopedAccessProvider ap(APP_LABEL_2, APP_1, GROUP_1);
+        ScopedAppContext ctx(APP_LABEL_2, APP_1, GROUP_1);
 
         // check that app can't access other aliases for which permission has been revoked
         check_alias_count(count - 2);
@@ -452,7 +452,7 @@ RUNNER_TEST(T3031_manager_deprecated_access_allowed, RemoveDataEnv<APP_1>)
 {
     // prepare: add data
     {
-        ScopedAccessProvider ap(APP_LABEL_1, APP_1, GROUP_1);
+        ScopedAppContext ctx(APP_LABEL_1, APP_1, GROUP_1);
         save_data(TEST_ALIAS, TEST_DATA);
 
         allow_access_deprecated(TEST_ALIAS, APP_LABEL_2, CKMC_AR_READ);
@@ -460,7 +460,7 @@ RUNNER_TEST(T3031_manager_deprecated_access_allowed, RemoveDataEnv<APP_1>)
 
     // test accessibility from another label
     {
-        ScopedAccessProvider ap(APP_LABEL_2, APP_1, GROUP_1);
+        ScopedAppContext ctx(APP_LABEL_2, APP_1, GROUP_1);
 
         check_read_allowed(aliasWithLabel(APP_LABEL_1, TEST_ALIAS).c_str(), TEST_DATA);
     }
@@ -471,7 +471,7 @@ RUNNER_TEST(T3032_manager_deprecated_access_allowed_with_remove, RemoveDataEnv<A
 {
     // prepare: add data
     {
-        ScopedAccessProvider ap(APP_LABEL_1, APP_1, GROUP_1);
+        ScopedAppContext ctx(APP_LABEL_1, APP_1, GROUP_1);
         save_data(TEST_ALIAS, TEST_DATA);
 
         allow_access_deprecated(TEST_ALIAS, APP_LABEL_2, CKMC_AR_READ_REMOVE);
@@ -479,7 +479,7 @@ RUNNER_TEST(T3032_manager_deprecated_access_allowed_with_remove, RemoveDataEnv<A
 
     // test accessibility from another label
     {
-        ScopedAccessProvider ap(APP_LABEL_2, APP_1, GROUP_1);
+        ScopedAppContext ctx(APP_LABEL_2, APP_1, GROUP_1);
 
         check_read_allowed(aliasWithLabel(APP_LABEL_1, TEST_ALIAS).c_str(), TEST_DATA);
     }
@@ -490,7 +490,7 @@ RUNNER_TEST(T3033_manager_deprecated_access_allowed_remove_denied, RemoveDataEnv
 {
     // prepare: add data
     {
-        ScopedAccessProvider ap(APP_LABEL_1, APP_1, GROUP_1);
+        ScopedAppContext ctx(APP_LABEL_1, APP_1, GROUP_1);
         save_data(TEST_ALIAS, TEST_DATA);
 
         allow_access_deprecated(TEST_ALIAS, APP_LABEL_2, CKMC_AR_READ);
@@ -498,7 +498,7 @@ RUNNER_TEST(T3033_manager_deprecated_access_allowed_remove_denied, RemoveDataEnv
 
     // test accessibility from another label
     {
-        ScopedAccessProvider ap(APP_LABEL_2, APP_1, GROUP_1);
+        ScopedAppContext ctx(APP_LABEL_2, APP_1, GROUP_1);
 
         std::string TEST_ALIAS_adr = aliasWithLabel(APP_LABEL_1, TEST_ALIAS);
         check_remove_denied(TEST_ALIAS_adr.c_str());
@@ -511,7 +511,7 @@ RUNNER_TEST(T3034_manager_deprecated_remove_allowed, RemoveDataEnv<APP_1>)
 {
     // prepare: add data
     {
-        ScopedAccessProvider ap(APP_LABEL_1, APP_1, GROUP_1);
+        ScopedAppContext ctx(APP_LABEL_1, APP_1, GROUP_1);
         save_data(TEST_ALIAS, TEST_DATA);
 
         allow_access_deprecated(TEST_ALIAS, APP_LABEL_2, CKMC_AR_READ_REMOVE);
@@ -519,7 +519,7 @@ RUNNER_TEST(T3034_manager_deprecated_remove_allowed, RemoveDataEnv<APP_1>)
 
     // test accessibility from another label
     {
-        ScopedAccessProvider ap(APP_LABEL_2, APP_1, GROUP_1);
+        ScopedAppContext ctx(APP_LABEL_2, APP_1, GROUP_1);
 
         check_remove_allowed(aliasWithLabel(APP_LABEL_1, TEST_ALIAS).c_str());
     }
@@ -541,7 +541,7 @@ RUNNER_TEST(T3101_control_allow_access_invalid, RemoveDataEnv<APP_1>)
 {
     // prepare: add data
     {
-        ScopedAccessProvider ap(APP_LABEL_1, APP_1, GROUP_1);
+        ScopedAppContext ctx(APP_LABEL_1, APP_1, GROUP_1);
         save_data(TEST_ALIAS, TEST_DATA);
     }
 
@@ -562,7 +562,7 @@ RUNNER_TEST(T3102_control_deny_access_invalid, RemoveDataEnv<APP_1>)
 {
     // prepare: add data
     {
-        ScopedAccessProvider ap(APP_LABEL_1, APP_1, GROUP_1);
+        ScopedAppContext ctx(APP_LABEL_1, APP_1, GROUP_1);
         save_data(TEST_ALIAS, TEST_DATA);
     }
 
@@ -600,7 +600,7 @@ RUNNER_TEST(T3105_control_remove_non_existing_access, RemoveDataEnv<APP_1>)
 {
     // prepare: add data
     {
-        ScopedAccessProvider ap(APP_LABEL_1, APP_1, GROUP_1);
+        ScopedAppContext ctx(APP_LABEL_1, APP_1, GROUP_1);
         save_data(TEST_ALIAS, TEST_DATA);
     }
 
@@ -613,7 +613,7 @@ RUNNER_TEST(T3105_control_remove_non_existing_access, RemoveDataEnv<APP_1>)
 RUNNER_TEST(T3106_control_allow_access_to_myself, RemoveDataEnv<APP_1>)
 {
     // prepare: add data
-    ScopedAccessProvider ap(APP_LABEL_1, APP_1, GROUP_1);
+    ScopedAppContext ctx(APP_LABEL_1, APP_1, GROUP_1);
     save_data(TEST_ALIAS, TEST_DATA);
 
     // test
@@ -628,7 +628,7 @@ RUNNER_CHILD_TEST(T3110_control_allow_access_as_user, RemoveDataEnv<APP_1>)
     RUNNER_IGNORED_MSG("Disabled until labeled sockets not available");
 
     // prepare: add data
-    ScopedAccessProvider ap(APP_LABEL_1, APP_1, GROUP_1);
+    ScopedAppContext ctx(APP_LABEL_1, APP_1, GROUP_1);
     save_data(TEST_ALIAS, TEST_DATA);
 
     // test
@@ -643,7 +643,7 @@ RUNNER_CHILD_TEST(T3111_control_deny_access_as_user, RemoveDataEnv<APP_1>)
     RUNNER_IGNORED_MSG("Disabled until labeled sockets not available");
 
     // prepare: add data
-    ScopedAccessProvider ap(APP_LABEL_1, APP_1, GROUP_1);
+    ScopedAppContext ctx(APP_LABEL_1, APP_1, GROUP_1);
     save_data(TEST_ALIAS, TEST_DATA);
 
     // test
@@ -657,13 +657,13 @@ RUNNER_TEST(T3121_control_access_allowed, RemoveDataEnv<APP_1>)
 {
     // prepare: add data
     {
-        ScopedAccessProvider ap(APP_LABEL_1, APP_1, GROUP_1);
+        ScopedAppContext ctx(APP_LABEL_1, APP_1, GROUP_1);
         save_data(TEST_ALIAS, TEST_DATA);
     }
 
     allow_access_by_adm(APP_1, APP_LABEL_1, TEST_ALIAS, APP_LABEL_2, CKMC_PERMISSION_READ);
     {
-        ScopedAccessProvider ap(APP_LABEL_2, APP_1, GROUP_1);
+        ScopedAppContext ctx(APP_LABEL_2, APP_1, GROUP_1);
 
         check_read_allowed(aliasWithLabel(APP_LABEL_1, TEST_ALIAS).c_str(), TEST_DATA);
     }
@@ -674,13 +674,13 @@ RUNNER_TEST(T3122_control_access_allowed_with_remove, RemoveDataEnv<APP_1>)
 {
     // prepare: add data
     {
-        ScopedAccessProvider ap(APP_LABEL_1, APP_1, GROUP_1);
+        ScopedAppContext ctx(APP_LABEL_1, APP_1, GROUP_1);
         save_data(TEST_ALIAS, TEST_DATA);
     }
 
     allow_access_by_adm(APP_1, APP_LABEL_1, TEST_ALIAS, APP_LABEL_2, CKMC_PERMISSION_READ | CKMC_PERMISSION_REMOVE);
     {
-        ScopedAccessProvider ap(APP_LABEL_2, APP_1, GROUP_1);
+        ScopedAppContext ctx(APP_LABEL_2, APP_1, GROUP_1);
 
         check_read_allowed(aliasWithLabel(APP_LABEL_1, TEST_ALIAS).c_str(), TEST_DATA);
     }
@@ -691,13 +691,13 @@ RUNNER_TEST(T3122_control_access_allowed_remove_denied, RemoveDataEnv<APP_1>)
 {
     // prepare: add data
     {
-        ScopedAccessProvider ap(APP_LABEL_1, APP_1, GROUP_1);
+        ScopedAppContext ctx(APP_LABEL_1, APP_1, GROUP_1);
         save_data(TEST_ALIAS, TEST_DATA);
     }
 
     allow_access_by_adm(APP_1, APP_LABEL_1, TEST_ALIAS, APP_LABEL_2, CKMC_PERMISSION_READ);
     {
-        ScopedAccessProvider ap(APP_LABEL_2, APP_1, GROUP_1);
+        ScopedAppContext ctx(APP_LABEL_2, APP_1, GROUP_1);
 
         check_remove_denied(aliasWithLabel(APP_LABEL_1, TEST_ALIAS).c_str());
     }
@@ -708,13 +708,13 @@ RUNNER_TEST(T3125_control_remove_allowed, RemoveDataEnv<APP_1>)
 {
     // prepare: add data
     {
-        ScopedAccessProvider ap(APP_LABEL_1, APP_1, GROUP_1);
+        ScopedAppContext ctx(APP_LABEL_1, APP_1, GROUP_1);
         save_data(TEST_ALIAS, TEST_DATA);
     }
 
     allow_access_by_adm(APP_1, APP_LABEL_1, TEST_ALIAS, APP_LABEL_2, CKMC_PERMISSION_READ | CKMC_PERMISSION_REMOVE);
     {
-        ScopedAccessProvider ap(APP_LABEL_2, APP_1, GROUP_1);
+        ScopedAppContext ctx(APP_LABEL_2, APP_1, GROUP_1);
 
         check_remove_allowed(aliasWithLabel(APP_LABEL_1, TEST_ALIAS).c_str());
     }
@@ -726,7 +726,7 @@ RUNNER_TEST(T3126_control_double_allow, RemoveDataEnv<APP_1>)
 {
     // prepare: add data
     {
-        ScopedAccessProvider ap(APP_LABEL_1, APP_1, GROUP_1);
+        ScopedAppContext ctx(APP_LABEL_1, APP_1, GROUP_1);
         save_data(TEST_ALIAS, TEST_DATA);
     }
 
@@ -734,7 +734,7 @@ RUNNER_TEST(T3126_control_double_allow, RemoveDataEnv<APP_1>)
     allow_access_by_adm(APP_1, APP_LABEL_1, TEST_ALIAS, APP_LABEL_2, CKMC_PERMISSION_READ | CKMC_PERMISSION_REMOVE);
     allow_access_by_adm(APP_1, APP_LABEL_1, TEST_ALIAS, APP_LABEL_2, CKMC_PERMISSION_READ);
     {
-        ScopedAccessProvider ap(APP_LABEL_2, APP_1, GROUP_1);
+        ScopedAppContext ctx(APP_LABEL_2, APP_1, GROUP_1);
 
         std::string TEST_ALIAS_adr = aliasWithLabel(APP_LABEL_1, TEST_ALIAS);
         check_remove_denied(TEST_ALIAS_adr.c_str());
@@ -747,14 +747,14 @@ RUNNER_TEST(T3127_control_allow_deny, RemoveDataEnv<APP_1>)
 {
     // prepare: add data
     {
-        ScopedAccessProvider ap(APP_LABEL_1, APP_1, GROUP_1);
+        ScopedAppContext ctx(APP_LABEL_1, APP_1, GROUP_1);
         save_data(TEST_ALIAS, TEST_DATA);
     }
 
     std::string TEST_ALIAS_adr = aliasWithLabel(APP_LABEL_1, TEST_ALIAS);
     allow_access_by_adm(APP_1, APP_LABEL_1, TEST_ALIAS, APP_LABEL_2, CKMC_PERMISSION_READ);
     {
-        ScopedAccessProvider ap(APP_LABEL_2, APP_1, GROUP_1);
+        ScopedAppContext ctx(APP_LABEL_2, APP_1, GROUP_1);
 
         check_remove_denied(TEST_ALIAS_adr.c_str());
         check_read_allowed(TEST_ALIAS_adr.c_str(), TEST_DATA);
@@ -762,7 +762,7 @@ RUNNER_TEST(T3127_control_allow_deny, RemoveDataEnv<APP_1>)
 
     deny_access_by_adm(APP_1, APP_LABEL_1, TEST_ALIAS, APP_LABEL_2);
     {
-        ScopedAccessProvider ap(APP_LABEL_2, APP_1, GROUP_1);
+        ScopedAppContext ctx(APP_LABEL_2, APP_1, GROUP_1);
 
         check_remove_not_visible(TEST_ALIAS_adr.c_str());
         check_read_not_visible(TEST_ALIAS_adr.c_str());
@@ -775,7 +775,7 @@ RUNNER_TEST(T3130_control_get_all_aliases, RemoveDataEnv<APP_1>)
     // prepare: add data
     size_t count;
     {
-        ScopedAccessProvider ap(APP_LABEL_1, APP_1, GROUP_1);
+        ScopedAppContext ctx(APP_LABEL_1, APP_1, GROUP_1);
         save_data(TEST_ALIAS, TEST_DATA);
         save_data(TEST_ALIAS2, TEST_DATA);
 
@@ -784,7 +784,7 @@ RUNNER_TEST(T3130_control_get_all_aliases, RemoveDataEnv<APP_1>)
 
     allow_access_by_adm(APP_1, APP_LABEL_1, TEST_ALIAS, APP_LABEL_2, CKMC_PERMISSION_READ);
     {
-        ScopedAccessProvider ap(APP_LABEL_2, APP_1, GROUP_1);
+        ScopedAppContext ctx(APP_LABEL_2, APP_1, GROUP_1);
 
         // check that app can access other aliases when it has permission
         check_alias_count(count - 1);
@@ -797,7 +797,7 @@ RUNNER_TEST(T3130_control_get_all_aliases, RemoveDataEnv<APP_1>)
 
     deny_access_by_adm(APP_1, APP_LABEL_1, TEST_ALIAS, APP_LABEL_2);
     {
-        ScopedAccessProvider ap(APP_LABEL_2, APP_1, GROUP_1);
+        ScopedAppContext ctx(APP_LABEL_2, APP_1, GROUP_1);
 
         // check that app can't access other aliases for which permission has been revoked
         check_alias_count(count - 2);
@@ -809,7 +809,7 @@ RUNNER_TEST(T3140_control_allow_invalid_user, RemoveDataEnv<APP_1>)
 {
     // prepare: add data
     {
-        ScopedAccessProvider ap(APP_LABEL_1, APP_1, GROUP_1);
+        ScopedAppContext ctx(APP_LABEL_1, APP_1, GROUP_1);
         save_data(TEST_ALIAS, TEST_DATA);
     }
 
@@ -823,7 +823,7 @@ RUNNER_TEST(T3141_control_deny_invalid_user, RemoveDataEnv<APP_1>)
 {
     // prepare: add data
     {
-        ScopedAccessProvider ap(APP_LABEL_1, APP_1, GROUP_1);
+        ScopedAppContext ctx(APP_LABEL_1, APP_1, GROUP_1);
         save_data(TEST_ALIAS, TEST_DATA);
     }
 
@@ -837,13 +837,13 @@ RUNNER_TEST(T3142_control_deprecated_access_allowed, RemoveDataEnv<APP_1>)
 {
     // prepare: add data
     {
-        ScopedAccessProvider ap(APP_LABEL_1, APP_1, GROUP_1);
+        ScopedAppContext ctx(APP_LABEL_1, APP_1, GROUP_1);
         save_data(TEST_ALIAS, TEST_DATA);
     }
 
     allow_access_deprecated_by_adm(APP_1, APP_LABEL_1, TEST_ALIAS, APP_LABEL_2, CKMC_AR_READ);
     {
-        ScopedAccessProvider ap(APP_LABEL_2, APP_1, GROUP_1);
+        ScopedAppContext ctx(APP_LABEL_2, APP_1, GROUP_1);
 
         check_read_allowed(aliasWithLabel(APP_LABEL_1, TEST_ALIAS).c_str(), TEST_DATA);
     }
@@ -854,13 +854,13 @@ RUNNER_TEST(T3143_control_deprecated_access_allowed_with_remove, RemoveDataEnv<A
 {
     // prepare: add data
     {
-        ScopedAccessProvider ap(APP_LABEL_1, APP_1, GROUP_1);
+        ScopedAppContext ctx(APP_LABEL_1, APP_1, GROUP_1);
         save_data(TEST_ALIAS, TEST_DATA);
     }
 
     allow_access_deprecated_by_adm(APP_1, APP_LABEL_1, TEST_ALIAS, APP_LABEL_2, CKMC_AR_READ_REMOVE);
     {
-        ScopedAccessProvider ap(APP_LABEL_2, APP_1, GROUP_1);
+        ScopedAppContext ctx(APP_LABEL_2, APP_1, GROUP_1);
 
         check_read_allowed(aliasWithLabel(APP_LABEL_1, TEST_ALIAS).c_str(), TEST_DATA);
     }
@@ -871,13 +871,13 @@ RUNNER_TEST(T3144_control_deprecated_access_allowed_remove_denied, RemoveDataEnv
 {
     // prepare: add data
     {
-        ScopedAccessProvider ap(APP_LABEL_1, APP_1, GROUP_1);
+        ScopedAppContext ctx(APP_LABEL_1, APP_1, GROUP_1);
         save_data(TEST_ALIAS, TEST_DATA);
     }
 
     allow_access_deprecated_by_adm(APP_1, APP_LABEL_1, TEST_ALIAS, APP_LABEL_2, CKMC_AR_READ);
     {
-        ScopedAccessProvider ap(APP_LABEL_2, APP_1, GROUP_1);
+        ScopedAppContext ctx(APP_LABEL_2, APP_1, GROUP_1);
 
         check_remove_denied(aliasWithLabel(APP_LABEL_1, TEST_ALIAS).c_str());
     }
@@ -888,13 +888,13 @@ RUNNER_TEST(T3145_control_deprecated_remove_allowed, RemoveDataEnv<APP_1>)
 {
     // prepare: add data
     {
-        ScopedAccessProvider ap(APP_LABEL_1, APP_1, GROUP_1);
+        ScopedAppContext ctx(APP_LABEL_1, APP_1, GROUP_1);
         save_data(TEST_ALIAS, TEST_DATA);
     }
 
     allow_access_deprecated_by_adm(APP_1, APP_LABEL_1, TEST_ALIAS, APP_LABEL_2, CKMC_AR_READ_REMOVE);
     {
-        ScopedAccessProvider ap(APP_LABEL_2, APP_1, GROUP_1);
+        ScopedAppContext ctx(APP_LABEL_2, APP_1, GROUP_1);
 
         check_remove_allowed(aliasWithLabel(APP_LABEL_1, TEST_ALIAS).c_str());
     }
@@ -943,7 +943,7 @@ RUNNER_TEST(utc_ckmc_get_data_alias_info_list_p1)
 
 RUNNER_TEST(utc_ckmc_get_data_alias_info_list_p2, RemoveDataEnv<APP_1>)
 {
-    ScopedAccessProvider ap(APP_LABEL_1, APP_1, GROUP_1);
+    ScopedAppContext ctx(APP_LABEL_1, APP_1, GROUP_1);
     save_data(TEST_ALIAS, TEST_DATA);
 
     ckmc_alias_info_list_s* ppalias_list = NULL;
index e8988de..f3de2bb 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright (c) 2015 - 2019 Samsung Electronics Co.
+ *  Copyright (c) 2015 - 2020 Samsung Electronics Co.
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -26,7 +26,7 @@
 #include <ckm/ckm-control.h>
 #include <ckm/ckm-manager.h>
 #include <ckmc/ckmc-manager.h>
-#include <access_provider2.h>
+#include <scoped-app-context.h>
 #include <fstream>
 #include <ios>
 #include <unistd.h>
@@ -153,8 +153,7 @@ RUNNER_TEST(T6010_PARSE_XML_FILE_AT_STARTUP)
     // [test2]
     {
         ScopedDBUnlock unlock(USER_APP, APP_PASS);
-        ScopedAccessProvider ap(TEST_LABEL);
-        ap.applyAndSwithToUser(USER_APP, GROUP_APP);
+        ScopedAppContext ctx(TEST_LABEL, USER_APP, GROUP_APP);
 
         check_key(XML_1_EXPECTED_KEY_1_RSA.c_str(), CKMC_ERROR_NOT_EXPORTABLE);
         check_key_not_visible(XML_1_EXPECTED_KEY_2_RSA.c_str());
@@ -166,8 +165,7 @@ RUNNER_TEST(T6010_PARSE_XML_FILE_AT_STARTUP)
     // [test3]
     {
         ScopedDBUnlock unlock(USER_APP, APP_PASS);
-        ScopedAccessProvider ap(TEST_LABEL_2);
-        ap.applyAndSwithToUser(USER_APP, GROUP_APP);
+        ScopedAppContext ctx(TEST_LABEL_2, USER_APP, GROUP_APP);
 
         check_key_not_visible(XML_1_EXPECTED_KEY_1_RSA.c_str());
         check_key_allowed(XML_1_EXPECTED_KEY_2_RSA.c_str(), CKMC_KEY_RSA_PRIVATE);
index f750ebe..fd5cd13 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright (c) 2016 - 2019 Samsung Electronics Co., Ltd All Rights Reserved
+ *  Copyright (c) 2016 - 2020 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.
@@ -26,7 +26,7 @@
 
 #include <tests_common.h>
 #include <test-certs.h>
-#include <access_provider2.h>
+#include <scoped-app-context.h>
 #include <ckm-common.h>
 #include <ckm-privileged-common.h>
 
@@ -77,9 +77,7 @@ RUNNER_TEST(T1511_insert_data)
     CKM::Alias certimAlias("CertIM");
     {
         ScopedDBUnlock unlock(USER_TEST, APP_PASS);
-        ScopedAccessProvider ap(TEST_LABEL);
-        ap.allowAPI("key-manager::api-storage", "rw");
-        ap.applyAndSwithToUser(USER_TEST, GROUP_APP);
+        ScopedAppContext ctx(TEST_LABEL, USER_TEST, GROUP_APP);
 
         auto manager = CKM::Manager::create();
         RUNNER_ASSERT(CKM_API_SUCCESS == manager->saveCertificate(certeeAlias, certee, CKM::Policy()));
@@ -93,9 +91,7 @@ RUNNER_TEST(T1511_insert_data)
     // actual test
     {
         ScopedDBUnlock unlock(USER_TEST, APP_PASS);
-        ScopedAccessProvider ap(TEST_LABEL);
-        ap.allowAPI("key-manager::api-storage", "rw");
-        ap.applyAndSwithToUser(USER_TEST, GROUP_APP);
+        ScopedAppContext ctx(TEST_LABEL, USER_TEST, GROUP_APP);
 
         auto manager = CKM::Manager::create();
         int status1 = manager->saveCertificate(certeeAlias, certee, CKM::Policy());
@@ -120,15 +116,13 @@ RUNNER_TEST(T1701_init_unlock_key)
 {
     unlock_user_data(USER_TEST+1, "t170-special-password");
 
-    ScopedAccessProvider ap(TEST_LABEL);
-    ap.applyAndSwithToUser(USER_TEST+1, GROUP_APP);
+    ScopedAppContext ctx(TEST_LABEL, USER_TEST+1, GROUP_APP);
 }
 
 RUNNER_CHILD_TEST(T1702_insert_data)
 {
     int temp;
-    ScopedAccessProvider ap(TEST_LABEL);
-    ap.applyAndSwithToUser(USER_TEST+1, GROUP_APP);
+    ScopedAppContext ctx(TEST_LABEL, USER_TEST+1, GROUP_APP);
 
     auto certee = TestData::getTestCertificate(TestData::THIRD_PARTY_LEAF);
 
@@ -161,8 +155,7 @@ RUNNER_TEST(T1703_removeApplicationData)
 RUNNER_CHILD_TEST(T1704_data_test)
 {
     int temp;
-    ScopedAccessProvider ap(TEST_LABEL);
-    ap.applyAndSwithToUser(USER_TEST+1, GROUP_APP);
+    ScopedAppContext ctx(TEST_LABEL, USER_TEST+1, GROUP_APP);
 
     CKM::AliasVector av;
     auto manager = CKM::Manager::create();
@@ -209,8 +202,7 @@ RUNNER_TEST(T17101_init)
 RUNNER_CHILD_TEST(T17102_prep_data_01)
 {
     int temp;
-    ScopedAccessProvider ap(TEST_LABEL);
-    ap.applyAndSwithToUser(USER_TEST+2, GROUP_APP);
+    ScopedAppContext ctx(TEST_LABEL, USER_TEST+2, GROUP_APP);
 
     CKM::AliasVector av;
     auto manager = CKM::Manager::create();
@@ -228,8 +220,7 @@ RUNNER_CHILD_TEST(T17102_prep_data_01)
 RUNNER_CHILD_TEST(T17103_prep_data_02)
 {
     int temp;
-    ScopedAccessProvider ap(TEST_LABEL_2);
-    ap.applyAndSwithToUser(USER_TEST+2, GROUP_APP);
+    ScopedAppContext ctx(TEST_LABEL_2, USER_TEST+2, GROUP_APP);
 
     CKM::AliasVector av;
     auto manager = CKM::Manager::create();
@@ -247,8 +238,7 @@ RUNNER_CHILD_TEST(T17103_prep_data_02)
 RUNNER_CHILD_TEST(T17104_prep_data_03)
 {
     int temp;
-    ScopedAccessProvider ap(TEST_LABEL);
-    ap.applyAndSwithToUser(USER_TEST+3, GROUP_APP);
+    ScopedAppContext ctx(TEST_LABEL, USER_TEST+3, GROUP_APP);
 
     CKM::AliasVector av;
     auto manager = CKM::Manager::create();
@@ -266,8 +256,7 @@ RUNNER_CHILD_TEST(T17104_prep_data_03)
 RUNNER_CHILD_TEST(T17105_prep_data_04)
 {
     int temp;
-    ScopedAccessProvider ap(TEST_LABEL_2);
-    ap.applyAndSwithToUser(USER_TEST+3, GROUP_APP);
+    ScopedAppContext ctx(TEST_LABEL_2, USER_TEST+3, GROUP_APP);
 
     CKM::AliasVector av;
     auto manager = CKM::Manager::create();
@@ -298,8 +287,7 @@ RUNNER_TEST(T17106_remove_application)
 RUNNER_CHILD_TEST(T17107_check_data_01)
 {
     int temp;
-    ScopedAccessProvider ap(TEST_LABEL);
-    ap.applyAndSwithToUser(USER_TEST+2, GROUP_APP);
+    ScopedAppContext ctx(TEST_LABEL, USER_TEST+2, GROUP_APP);
 
     CKM::AliasVector av;
     auto manager = CKM::Manager::create();
@@ -315,8 +303,7 @@ RUNNER_CHILD_TEST(T17107_check_data_01)
 RUNNER_CHILD_TEST(T17108_check_data_02)
 {
     int temp;
-    ScopedAccessProvider ap(TEST_LABEL_2);
-    ap.applyAndSwithToUser(USER_TEST+2, GROUP_APP);
+    ScopedAppContext ctx(TEST_LABEL_2, USER_TEST+2, GROUP_APP);
 
     CKM::AliasVector av;
     auto manager = CKM::Manager::create();
@@ -342,9 +329,7 @@ RUNNER_TEST(T17109_unlock_user2)
 RUNNER_CHILD_TEST(T17110_check_data_03)
 {
     int temp;
-    ScopedAccessProvider ap(TEST_LABEL);
-    ap.allowAPI("key-manager::api-storage", "rw");
-    ap.applyAndSwithToUser(USER_TEST+3, GROUP_APP);
+    ScopedAppContext ctx(TEST_LABEL, USER_TEST+3, GROUP_APP);
 
     CKM::AliasVector av;
     auto manager = CKM::Manager::create();
@@ -360,9 +345,7 @@ RUNNER_CHILD_TEST(T17110_check_data_03)
 RUNNER_CHILD_TEST(T17111_check_data_04)
 {
     int temp;
-    ScopedAccessProvider ap(TEST_LABEL_2);
-    ap.allowAPI("key-manager::api-storage", "rw");
-    ap.applyAndSwithToUser(USER_TEST+3, GROUP_APP);
+    ScopedAppContext ctx(TEST_LABEL_2, USER_TEST+3, GROUP_APP);
 
     CKM::AliasVector av;
     auto manager = CKM::Manager::create();
diff --git a/src/ckm/privileged/scoped-app-context.cpp b/src/ckm/privileged/scoped-app-context.cpp
new file mode 100644 (file)
index 0000000..80f0df9
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2013 - 2020 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.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+/*
+ * @file        scoped-app-context.cpp
+ * @author      Bartlomiej Grzelewski (b.grzelewski@samsung.com)
+ * @author      Krzysztof Jackiewicz (k.jackiewicz@samsung.com)
+ * @version     1.0
+ * @brief       RAII guard for pretending to be an app (Smack, uid, gid).
+ */
+
+#include <ckm-common.h>
+#include <dpl/test/test_exception.h>
+#include <dpl/test/test_runner.h>
+#include <scoped-app-context.h>
+
+#include <unistd.h>
+
+ScopedAppContext::ScopedAppContext(const std::string& owner, uid_t user, gid_t group)
+    : m_context(SMACK_USER_APP_PREFIX + owner)
+    , m_oldUser(getuid())
+    , m_oldGroup(getgid())
+{
+    m_context.allowAccessFrom("System", "w");
+    m_context.allowAccessTo("System", "w");
+    m_context.allowAccessTo("System::Run", "wx"); // Necessary for logging with journald
+
+    m_context.applyRules();
+    m_processLabel = std::make_unique<ScopedProcessLabel>(m_context.applyLabelScoped());
+    m_context.applyUserSwitchEffective(user, group);
+}
+
+ScopedAppContext::~ScopedAppContext()
+{
+    try {
+        m_context.applyUserSwitchEffective(m_oldUser, m_oldGroup);
+        m_context.revokeRules();
+    } catch (const DPL::Test::TestException& e) {
+        RUNNER_ERROR_MSG("Exception in ScopedAppContext destructor: " << e.GetMessage());
+    }
+}
diff --git a/src/ckm/privileged/scoped-app-context.h b/src/ckm/privileged/scoped-app-context.h
new file mode 100644 (file)
index 0000000..eebf705
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2013 - 2020 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.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+/*
+ * @file        scoped-app-context.h
+ * @author      Bartlomiej Grzelewski (b.grzelewski@samsung.com)
+ * @version     1.0
+ * @brief       RAII guard for pretending to be an app (Smack, uid, gid).
+ */
+
+#pragma once
+
+#include <app_context.h>
+#include <scoped_process_label.h>
+
+#include <memory>
+#include <string>
+
+#include <sys/types.h>
+
+class ScopedAppContext {
+public:
+    ScopedAppContext(const std::string& owner, uid_t user, gid_t group);
+    ScopedAppContext(const ScopedAppContext&) = delete;
+    ScopedAppContext& operator=(const ScopedAppContext&) = delete;
+    ~ScopedAppContext();
+
+private:
+    AppContext m_context;
+    std::unique_ptr<ScopedProcessLabel> m_processLabel;
+    uid_t m_oldUser;
+    gid_t m_oldGroup;
+};
index e9c7a5d..1a4ee6e 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright (c) 2000 - 2015 Samsung Electronics Co.
+ *  Copyright (c) 2000 - 2020 Samsung Electronics Co.
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -24,7 +24,7 @@
 #include <ckm/ckm-control.h>
 #include <ckmc/ckmc-manager.h>
 #include <ckmc/ckmc-type.h>
-#include <access_provider2.h>
+#include <scoped-app-context.h>
 #include <unistd.h>
 #include <sys/types.h>
 
@@ -77,9 +77,7 @@ RUNNER_TEST(T5010_CLIENT_APP_LOCKED_PRIVATE_DB)
 
     // [test]
     {
-        ScopedAccessProvider ap(TEST_LABEL);
-        ap.allowAPI("key-manager::api-storage", "rw");
-        ap.applyAndSwithToUser(USER_APP, GROUP_APP);
+        ScopedAppContext ctx(TEST_LABEL, USER_APP, GROUP_APP);
 
         check_read(TEST_ALIAS, SYSTEM_LABEL, TEST_DATA, CKMC_ERROR_DB_LOCKED);
     }
@@ -97,9 +95,7 @@ RUNNER_TEST(T5020_CLIENT_APP_ADD_TO_PRIVATE_DB)
     {
         remove_user_data(USER_APP);
         ScopedDBUnlock unlock(USER_APP, APP_PASS);
-        ScopedAccessProvider ap(TEST_LABEL);
-        ap.allowAPI("key-manager::api-storage", "rw");
-        ap.applyAndSwithToUser(USER_APP, GROUP_APP);
+        ScopedAppContext ctx(TEST_LABEL, USER_APP, GROUP_APP);
 
         ScopedSaveData ssd(TEST_ALIAS, TEST_DATA);
         check_read(TEST_ALIAS, TEST_LABEL, TEST_DATA);
@@ -115,9 +111,7 @@ RUNNER_TEST(T5030_CLIENT_APP_TRY_ADDING_SYSTEM_ITEM, RemoveDataEnv<0, USER_APP>)
     // [test]
     {
         ScopedDBUnlock unlock(USER_APP, APP_PASS);
-        ScopedAccessProvider ap(TEST_LABEL);
-        ap.allowAPI("key-manager::api-storage", "rw");
-        ap.applyAndSwithToUser(USER_APP, GROUP_APP);
+        ScopedAppContext ctx(TEST_LABEL, USER_APP, GROUP_APP);
 
         save_data(aliasWithLabel(SYSTEM_LABEL, TEST_ALIAS).c_str(), TEST_DATA, CKMC_ERROR_PERMISSION_DENIED);
         check_read(TEST_ALIAS, SYSTEM_LABEL, TEST_DATA, CKMC_ERROR_DB_ALIAS_UNKNOWN);
@@ -140,9 +134,7 @@ RUNNER_TEST(T5031_CLIENT_APP_ACCESS_WITH_PERMISSION, RemoveDataEnv<0, USER_APP>)
     // [test]
     {
         ScopedDBUnlock unlock(USER_APP, APP_PASS);
-        ScopedAccessProvider ap(TEST_LABEL);
-        ap.allowAPI("key-manager::api-storage", "rw");
-        ap.applyAndSwithToUser(USER_APP, GROUP_APP);
+        ScopedAppContext ctx(TEST_LABEL, USER_APP, GROUP_APP);
 
         check_read(TEST_ALIAS, SYSTEM_LABEL, TEST_DATA);
     }
@@ -163,9 +155,7 @@ RUNNER_TEST(T5032_CLIENT_APP_ACCESS_NO_PERMISSION, RemoveDataEnv<0, USER_APP>)
     // [test]
     {
         ScopedDBUnlock unlock(USER_APP, APP_PASS);
-        ScopedAccessProvider ap(TEST_LABEL);
-        ap.allowAPI("key-manager::api-storage", "rw");
-        ap.applyAndSwithToUser(USER_APP, GROUP_APP);
+        ScopedAppContext ctx(TEST_LABEL, USER_APP, GROUP_APP);
 
         check_read(TEST_ALIAS, SYSTEM_LABEL, TEST_DATA, CKMC_ERROR_DB_ALIAS_UNKNOWN);
     }
@@ -194,9 +184,7 @@ RUNNER_TEST(T5033_CLIENT_APP_PERMISSION_REMOVAL, RemoveDataEnv<0, USER_APP>)
     // [test]
     {
         ScopedDBUnlock unlock(USER_APP, APP_PASS);
-        ScopedAccessProvider ap(TEST_LABEL);
-        ap.allowAPI("key-manager::api-storage", "rw");
-        ap.applyAndSwithToUser(USER_APP, GROUP_APP);
+        ScopedAppContext ctx(TEST_LABEL, USER_APP, GROUP_APP);
 
         check_read(TEST_ALIAS, SYSTEM_LABEL, TEST_DATA);
     }
@@ -207,9 +195,7 @@ RUNNER_TEST(T5033_CLIENT_APP_PERMISSION_REMOVAL, RemoveDataEnv<0, USER_APP>)
     // [test2]
     {
         ScopedDBUnlock unlock(USER_APP, APP_PASS);
-        ScopedAccessProvider ap(TEST_LABEL);
-        ap.allowAPI("key-manager::api-storage", "rw");
-        ap.applyAndSwithToUser(USER_APP, GROUP_APP);
+        ScopedAppContext ctx(TEST_LABEL, USER_APP, GROUP_APP);
 
         check_read(TEST_ALIAS, SYSTEM_LABEL, TEST_DATA, CKMC_ERROR_DB_ALIAS_UNKNOWN);
     }
@@ -225,9 +211,7 @@ RUNNER_TEST(T5034_CLIENT_APP_SET_READ_ACCESS, RemoveDataEnv<0, USER_APP>)
     // [test]
     {
         ScopedDBUnlock unlock(USER_APP, APP_PASS);
-        ScopedAccessProvider ap(TEST_LABEL);
-        ap.allowAPI("key-manager::api-storage", "rw");
-        ap.applyAndSwithToUser(USER_APP, GROUP_APP);
+        ScopedAppContext ctx(TEST_LABEL, USER_APP, GROUP_APP);
 
         ScopedSaveData ssdsystem_user(TEST_ALIAS, TEST_DATA);
         ScopedSaveData ssdsystem_system(TEST_SYSTEM_ALIAS.c_str(), TEST_DATA, CKMC_ERROR_PERMISSION_DENIED);
@@ -252,9 +236,7 @@ RUNNER_TEST(T5035_CLIENT_APP_TRY_REMOVING_SYSTEM_ITEM, RemoveDataEnv<0, USER_APP
     // [test]
     {
         ScopedDBUnlock unlock(USER_APP, APP_PASS);
-        ScopedAccessProvider ap(TEST_LABEL);
-        ap.allowAPI("key-manager::api-storage", "rw");
-        ap.applyAndSwithToUser(USER_APP, GROUP_APP);
+        ScopedAppContext ctx(TEST_LABEL, USER_APP, GROUP_APP);
 
         check_remove_denied(TEST_SYSTEM_ALIAS.c_str());
     }
@@ -285,9 +267,7 @@ RUNNER_TEST(T5036_CLIENT_LIST_ACCESSIBLE_ITEMS, RemoveDataEnv<0, USER_APP>)
     // [test2]
     {
         ScopedDBUnlock unlock(USER_APP, APP_PASS);
-        ScopedAccessProvider ap(TEST_LABEL);
-        ap.allowAPI("key-manager::api-storage", "rw");
-        ap.applyAndSwithToUser(USER_APP, GROUP_APP);
+        ScopedAppContext ctx(TEST_LABEL, USER_APP, GROUP_APP);
         ScopedSaveData user_data(TEST_ALIAS, TEST_DATA);
 
         check_alias_list({TEST_SYSTEM_ALIAS.c_str(),
@@ -304,9 +284,7 @@ RUNNER_TEST(T5037_CLIENT_APP_TRY_GENERATE_KEY_IN_SYSTEM_DB, RemoveDataEnv<USER_A
     // [test]
     {
         ScopedDBUnlock unlock(USER_APP, APP_PASS);
-        ScopedAccessProvider ap(TEST_LABEL);
-        ap.allowAPI("key-manager::api-storage", "rw");
-        ap.applyAndSwithToUser(USER_APP, GROUP_APP);
+        ScopedAppContext ctx(TEST_LABEL, USER_APP, GROUP_APP);
 
         std::string private_key_alias = aliasWithLabel(SYSTEM_LABEL, "sys-db-priv");
         std::string public_key_alias = aliasWithLabel(SYSTEM_LABEL, "sys-db-pub");
@@ -389,9 +367,7 @@ RUNNER_TEST(T5038_CLIENT_SERVER_CREATE_VERIFY_SYSTEM_DB, RemoveDataEnv<0,USER_AP
     // [test2]
     {
         ScopedDBUnlock unlock(USER_APP, APP_PASS);
-        ScopedAccessProvider ap(TEST_LABEL);
-        ap.allowAPI("key-manager::api-storage", "rw");
-        ap.applyAndSwithToUser(USER_APP, GROUP_APP);
+        ScopedAppContext ctx(TEST_LABEL, USER_APP, GROUP_APP);
 
         ckmc_hash_algo_e hash_algo = CKMC_HASH_SHA256;
         ckmc_rsa_padding_algo_e pad_algo = CKMC_PKCS1_PADDING;
@@ -454,9 +430,7 @@ RUNNER_TEST(T5041_SYSTEM_SVC_1234_ACCESS_DB, RemoveDataEnv<0>)
 
     // [test]
     {
-        ScopedAccessProvider ap(TEST_LABEL_2);
-        ap.allowAPI("key-manager::api-storage", "rw");
-        ap.applyAndSwithToUser(USER_SERVICE_2, GROUP_SERVICE_2);
+        ScopedAppContext ctx(TEST_LABEL_2, USER_SERVICE_2, GROUP_SERVICE_2);
 
         check_read(TEST_ALIAS, SYSTEM_LABEL, TEST_DATA);
     }
@@ -473,9 +447,7 @@ RUNNER_TEST(T5042_SYSTEM_SVC_1234_ADD_ITEM_TO_DB)
 
     // [prepare]
     {
-        ScopedAccessProvider ap(TEST_LABEL_2);
-        ap.allowAPI("key-manager::api-storage", "rw");
-        ap.applyAndSwithToUser(USER_SERVICE_2, GROUP_SERVICE_2);
+        ScopedAppContext ctx(TEST_LABEL_2, USER_SERVICE_2, GROUP_SERVICE_2);
 
         // [test]
         ScopedSaveData ssd(TEST_SYSTEM_ALIAS.c_str(), TEST_DATA);
@@ -497,9 +469,7 @@ RUNNER_TEST(T5043_SYSTEM_SVC_4999_ACCESS_DB, RemoveDataEnv<0>)
 
     // [test]
     {
-        ScopedAccessProvider ap(TEST_LABEL_2);
-        ap.allowAPI("key-manager::api-storage", "rw");
-        ap.applyAndSwithToUser(USER_SERVICE_MAX, GROUP_SERVICE_MAX);
+        ScopedAppContext ctx(TEST_LABEL_2, USER_SERVICE_MAX, GROUP_SERVICE_MAX);
 
         check_read(TEST_ALIAS, SYSTEM_LABEL, TEST_DATA);
     }
@@ -521,9 +491,7 @@ RUNNER_TEST(T5044_SYSTEM_SVC_5000_ACCESS_DB, RemoveDataEnv<0>)
 
     // [test]
     {
-        ScopedAccessProvider ap(TEST_LABEL_2);
-        ap.allowAPI("key-manager::api-storage", "rw");
-        ap.applyAndSwithToUser(USER_SERVICE_FAIL, GROUP_SERVICE_FAIL);
+        ScopedAppContext ctx(TEST_LABEL_2, USER_SERVICE_FAIL, GROUP_SERVICE_FAIL);
 
         check_read(TEST_ALIAS, SYSTEM_LABEL, TEST_DATA, CKMC_ERROR_DB_LOCKED);
     }
index b97fc80..367d1e0 100644 (file)
@@ -21,7 +21,7 @@ PKG_CHECK_MODULES(COMMON_TARGET_DEP
 #files to compile
 SET(COMMON_TARGET_TEST_SOURCES
     ${PROJECT_SOURCE_DIR}/src/common/tests_common.cpp
-    ${PROJECT_SOURCE_DIR}/src/common/access_provider.cpp
+    ${PROJECT_SOURCE_DIR}/src/common/app_context.cpp
     ${PROJECT_SOURCE_DIR}/src/common/smack_access.cpp
     ${PROJECT_SOURCE_DIR}/src/common/dbus_connection.cpp
     ${PROJECT_SOURCE_DIR}/src/common/dbus_message_in.cpp
diff --git a/src/common/access_provider.cpp b/src/common/access_provider.cpp
deleted file mode 100644 (file)
index fb53d86..0000000
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * Copyright (c) 2013 - 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.
- *    You may obtain a copy of the License at
- *
- *        http://www.apache.org/licenses/LICENSE-2.0
- *
- *    Unless required by applicable law or agreed to in writing, software
- *    distributed under the License is distributed on an "AS IS" BASIS,
- *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *    See the License for the specific language governing permissions and
- *    limitations under the License.
- */
-/*
- * @file        access_provider.cpp
- * @author      Bartlomiej Grzelewski (b.grzelewski@samsung.com)
- * @version     1.0
- * @brief       Common functions and macros used in security-tests package.
- */
-#include <sys/types.h>
-#include <unistd.h>
-#include <sys/smack.h>
-
-#include <map>
-
-#include <tests_common.h>
-
-#include <access_provider.h>
-#include <scoped_process_label.h>
-
-namespace SecurityServer {
-
-AccessProvider::AccessProvider(const std::string &myLabel)
-  : m_myLabel(myLabel)
-{}
-
-void AccessProvider::allowSS() {
-    m_smackAccess.add(m_myLabel, "System::Run", "x");
-}
-
-void AccessProvider::addSubjectRule(const std::string &subject, const std::string &rule) {
-    m_smackAccess.add(subject, m_myLabel, rule);
-}
-
-void AccessProvider::addObjectRule(const std::string &object, const std::string &rule) {
-    m_smackAccess.add(m_myLabel, object, rule);
-}
-
-void AccessProvider::apply() {
-    m_smackAccess.apply();
-}
-
-void AccessProvider::applyAndSwithToUser(int uid, int gid) {
-    RUNNER_ASSERT_MSG(0 == smack_revoke_subject(m_myLabel.c_str()),
-        "Error in smack_revoke_subject(" << m_myLabel << ")");
-    apply();
-    ScopedProcessLabel spl(m_myLabel, false);
-    RUNNER_ASSERT_MSG(0 == setgid(gid),
-        "Error in setgid.");
-    RUNNER_ASSERT_MSG(0 == setuid(uid),
-        "Error in setuid.");
-}
-
-} // namespace SecurityServer
-
diff --git a/src/common/app_context.cpp b/src/common/app_context.cpp
new file mode 100644 (file)
index 0000000..0a42fe7
--- /dev/null
@@ -0,0 +1,91 @@
+/*
+ * Copyright (c) 2013 - 2020 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.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+/*
+ * @file        app_context.cpp
+ * @author      Bartlomiej Grzelewski (b.grzelewski@samsung.com)
+ * @version     1.0
+ * @brief       Common functions and macros used in security-tests package.
+ */
+
+#include <app_context.h>
+#include <scoped_process_label.h>
+#include <tests_common.h>
+
+#include <map>
+
+#include <sys/smack.h>
+#include <unistd.h>
+
+AppContext::AppContext(const std::string& label)
+    : m_label(label)
+{
+}
+
+void AppContext::allowAccessFrom(const std::string& subject, const std::string& rule)
+{
+    m_smackAccess.add(subject, m_label, rule);
+}
+
+void AppContext::allowAccessTo(const std::string& object, const std::string& rule)
+{
+    m_smackAccess.add(m_label, object, rule);
+}
+
+void AppContext::apply(uid_t user, gid_t group)
+{
+    revokeAccessToAll();
+    applyRules();
+    applyLabel();
+    applyUserSwitch(user, group);
+}
+
+void AppContext::applyLabel()
+{
+    ScopedProcessLabel spl(m_label, false);
+}
+
+ScopedProcessLabel AppContext::applyLabelScoped()
+{
+    return ScopedProcessLabel(m_label, true);
+}
+
+void AppContext::applyRules()
+{
+    m_smackAccess.apply();
+}
+
+void AppContext::applyUserSwitch(uid_t user, gid_t group)
+{
+    RUNNER_ASSERT_MSG(0 == setgid(group), "Error in setgid.");
+    RUNNER_ASSERT_MSG(0 == setuid(user), "Error in setuid.");
+}
+
+void AppContext::applyUserSwitchEffective(uid_t user, gid_t group)
+{
+    RUNNER_ASSERT_MSG(0 == setegid(group), "Error in setegid.");
+    RUNNER_ASSERT_MSG(0 == seteuid(user), "Error in seteuid.");
+}
+
+void AppContext::revokeAccessToAll()
+{
+    RUNNER_ASSERT_MSG(0 == smack_revoke_subject(m_label.c_str()),
+        "Error in smack_revoke_subject(" << m_label << ")");
+}
+
+void AppContext::revokeRules()
+{
+    m_smackAccess.clear();
+}
similarity index 51%
rename from src/common/access_provider.h
rename to src/common/app_context.h
index 26124b4..b83282f 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2013 - 2020 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.
  *    limitations under the License.
  */
 /*
- * @file        access_provider.h
+ * @file        app_context.h
  * @author      Bartlomiej Grzelewski (b.grzelewski@samsung.com)
  * @version     1.0
  * @brief       Common functions and macros used in security-tests package.
  */
-#ifndef _ACCESS_FOR_DUMMIES_H_
-#define _ACCESS_FOR_DUMMIES_H_
 
-#include <string>
+#pragma once
 
+#include <scoped_process_label.h>
 #include <smack_access.h>
 
-namespace SecurityServer {
-
-class AccessProvider {
-public:
-    AccessProvider(const std::string &myLabel);
+#include <string>
 
-    AccessProvider(const AccessProvider &second) = delete;
-    AccessProvider& operator=(const AccessProvider &second) = delete;
+#include <sys/types.h>
 
-    void addSubjectRule(const std::string &subject, const std::string &rule);
-    void addObjectRule(const std::string &object, const std::string &rule);
-    void allowSS();
-    void apply();
-    void applyAndSwithToUser(int uid, int gid);
+class AppContext {
+public:
+    AppContext(const std::string& label);
+    AppContext(const AppContext&) = delete;
+    AppContext& operator=(const AppContext&) = delete;
+
+    void allowAccessFrom(const std::string& subject, const std::string& rule);
+    void allowAccessTo(const std::string& object, const std::string& rule);
+
+    void apply(uid_t user, gid_t group);
+    void applyLabel();
+    ScopedProcessLabel applyLabelScoped();
+    void applyRules();
+    void applyUserSwitch(uid_t user, gid_t group);
+    void applyUserSwitchEffective(uid_t user, gid_t group);
+    void revokeAccessToAll();
+    void revokeRules();
 
-    virtual ~AccessProvider(){}
 private:
-    std::string m_myLabel;;
+    std::string m_label;
     SmackAccess m_smackAccess;
 };
-
-} // namespace SecurityServer
-
-#endif // _ACCESS_FOR_DUMMIES_H_
-
index aa642fe..b7e450c 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
+ *  Copyright (c) 2019 - 2020 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.
@@ -131,6 +131,24 @@ ScopedProcessLabel::ScopedProcessLabel(std::string label, bool restore) :
        smackSetLabelForSelf(m_label);
 }
 
+ScopedProcessLabel::ScopedProcessLabel(ScopedProcessLabel&& other)
+       : m_label(std::move(other.m_label))
+       , m_originalLabel(std::move(other.m_originalLabel))
+       , m_originalOnlycap(std::move(other.m_originalOnlycap))
+{
+       other.m_originalLabel.clear();
+}
+
+ScopedProcessLabel& ScopedProcessLabel::operator=(ScopedProcessLabel&& other)
+{
+       m_label = std::move(other.m_label);
+       m_originalLabel = std::move(other.m_originalLabel);
+       m_originalOnlycap = std::move(other.m_originalOnlycap);
+
+       other.m_originalLabel.clear();
+       return *this;
+}
+
 ScopedProcessLabel::~ScopedProcessLabel()
 {
        // it has to be restored
index 5cb0dfc..a90b993 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
+ *  Copyright (c) 2019 - 2020 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.
@@ -34,6 +34,8 @@ class ScopedProcessLabel: public DPL::Noncopyable
 public:
        // if restore == true the original label will be restored
        explicit ScopedProcessLabel(std::string label, bool restore = true);
+       ScopedProcessLabel(ScopedProcessLabel&& other);
+       ScopedProcessLabel& operator=(ScopedProcessLabel&& other);
        ~ScopedProcessLabel();
 
 private:
index 354b997..e461a31 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2013 - 2020 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.
@@ -50,6 +50,11 @@ void SmackAccess::apply() {
         "Error in smack_accessses_apply.");
 }
 
+void SmackAccess::clear() {
+    RUNNER_ASSERT_MSG(0 == smack_accesses_clear(m_handle),
+        "Error in smack_accesses_clear.");
+}
+
 SmackAccess::~SmackAccess() {
     if (m_handle)
         smack_accesses_free(m_handle);
index f20842b..0d3f227 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2013 - 2020 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.
@@ -36,6 +36,7 @@ public:
              const std::string &object,
              const std::string &rights);
     void apply();
+    void clear();
     virtual ~SmackAccess();
 private:
     struct smack_accesses *m_handle;
index b8d7f13..86ec5e0 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015-2019 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2015-2020 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.
@@ -34,7 +34,7 @@
 #include <systemd/sd-bus.h>
 
 #include <tests_common.h>
-#include <access_provider.h>
+#include <app_context.h>
 #include <dpl/test/test_runner.h>
 #include <memory.h>
 #include <synchronization_pipe.h>
@@ -87,8 +87,8 @@ cynara_user_creds getUserDefaultMethod() {
 
 void udsServer(SynchronizationPipe &pipe, const struct sockaddr_un &sockaddr,
                const struct ProcessCredentials &peerCredentials) {
-    SecurityServer::AccessProvider ap(peerCredentials.label());
-    ap.applyAndSwithToUser(peerCredentials.uid(), peerCredentials.gid());
+    AppContext ctx(peerCredentials.label());
+    ctx.apply(peerCredentials.uid(), peerCredentials.gid());
     pipe.claimChildEp();
 
     int sock = UDSHelpers::createServer(&sockaddr);
@@ -243,19 +243,15 @@ DBusConnectionPtr createDBusConnection(const std::string &name) {
 
 void dbusServer(SynchronizationPipe &pipe, const std::string &requestedName,
                 const ProcessCredentials &peerCredentials) {
-    // for DBus connection, System must have access to our peer creds as well.
-    SecurityServer::AccessProvider systemAp("System");
-    systemAp.addObjectRule(peerCredentials.label(), "rwx");
-    systemAp.apply();
-
-    SecurityServer::AccessProvider ap(peerCredentials.label());
-    ap.addObjectRule("System", "w");
-    ap.addObjectRule("System::Run", "x");
-    ap.addObjectRule("System::Shared", "rwx"); // for GDB
-    ap.addSubjectRule("System::Privileged", "rwx"); // for piping
-    ap.addObjectRule("System::Privileged", "rwx"); // for GDB and piping
-    ap.addObjectRule("User", "r"); // for /usr/lib/debug access
-    ap.applyAndSwithToUser(peerCredentials.uid(), peerCredentials.gid());
+    AppContext ctx(peerCredentials.label());
+    ctx.allowAccessFrom("System", "rwx"); // for DBus connection
+    ctx.allowAccessFrom("System::Privileged", "rwx"); // for piping
+    ctx.allowAccessTo("System", "w");
+    ctx.allowAccessTo("System::Privileged", "rwx"); // for GDB and piping
+    ctx.allowAccessTo("System::Run", "x");
+    ctx.allowAccessTo("System::Shared", "rwx"); // for GDB
+    ctx.allowAccessTo("User", "r"); // for /usr/lib/debug access
+    ctx.apply(peerCredentials.uid(), peerCredentials.gid());
     pipe.claimChildEp();
 
     auto conn = createDBusConnection(requestedName);
diff --git a/src/libsmack-tests/CMakeLists.txt b/src/libsmack-tests/CMakeLists.txt
deleted file mode 100644 (file)
index 857d9ef..0000000
+++ /dev/null
@@ -1,120 +0,0 @@
-# Copyright (c) 2012-2015 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.
-#   You may obtain a copy of the License at
-#
-#       http://www.apache.org/licenses/LICENSE-2.0
-#
-#   Unless required by applicable law or agreed to in writing, software
-#   distributed under the License is distributed on an "AS IS" BASIS,
-#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-#   See the License for the specific language governing permissions and
-#   limitations under the License.
-
-# @file        CMakeLists.txt
-# @author      Pawel Polawski (p.polawski@samsung.com)
-# @version     0.1
-# @brief
-#
-INCLUDE(FindPkgConfig)
-SET(TARGET_TEST "libsmack-test")
-
-#dependencies
-PKG_CHECK_MODULES(TARGET_DEP
-    libsmack
-    REQUIRED
-    )
-
-#files to compile
-SET(TARGET_TEST_SOURCES
-    ${PROJECT_SOURCE_DIR}/src/libsmack-tests/libsmack-test.cpp
-    ${PROJECT_SOURCE_DIR}/src/libsmack-tests/test_cases.cpp
-    )
-
-#header directories
-INCLUDE_DIRECTORIES(SYSTEM
-    ${TARGET_DEP_INCLUDE_DIRS}
-    )
-
-INCLUDE_DIRECTORIES(
-    ${PROJECT_SOURCE_DIR}/src/common/
-    )
-
-#preprocessor definitions
-#ADD_DEFINITIONS("-DDPL_LOGS_ENABLED")
-
-#output format
-ADD_EXECUTABLE(${TARGET_TEST} ${TARGET_TEST_SOURCES})
-
-#linker directories
-TARGET_LINK_LIBRARIES(${TARGET_TEST}
-    ${TARGET_DEP_LIBRARIES}
-    dpl-test-framework
-    tests-common
-    )
-
-#place for output file
-INSTALL(TARGETS ${TARGET_TEST}
-    DESTINATION /usr/bin
-    PERMISSIONS OWNER_READ
-                OWNER_WRITE
-                OWNER_EXECUTE
-                GROUP_READ
-                GROUP_EXECUTE
-                WORLD_READ
-                WORLD_EXECUTE
-    )
-
-#place for additional files
-INSTALL(FILES
-    ${PROJECT_SOURCE_DIR}/src/libsmack-tests/test_smack_rules
-    DESTINATION /etc/smack
-    PERMISSIONS
-    OWNER_READ
-    OWNER_EXECUTE
-    GROUP_READ
-    GROUP_EXECUTE
-    WORLD_READ
-    WORLD_EXECUTE
-  )
-
-#place for full rules
-INSTALL(FILES
-    ${PROJECT_SOURCE_DIR}/src/libsmack-tests/test_smack_rules_full
-    DESTINATION /etc/smack
-    PERMISSIONS
-    OWNER_READ
-    GROUP_READ
-    WORLD_READ
-  )
-
-#place for rules2
-INSTALL(FILES
-    ${PROJECT_SOURCE_DIR}/src/libsmack-tests/test_smack_rules2
-    DESTINATION /etc/smack
-    PERMISSIONS
-    OWNER_READ
-    GROUP_READ
-    WORLD_READ
-  )
-
-#place for rules3
-INSTALL(FILES
-    ${PROJECT_SOURCE_DIR}/src/libsmack-tests/test_smack_rules3
-    DESTINATION /etc/smack
-    PERMISSIONS
-    OWNER_READ
-    GROUP_READ
-    WORLD_READ
-  )
-
-#place for rules4
-INSTALL(FILES
-    ${PROJECT_SOURCE_DIR}/src/libsmack-tests/test_smack_rules4
-    DESTINATION /etc/smack
-    PERMISSIONS
-    OWNER_READ
-    GROUP_READ
-    WORLD_READ
-  )
diff --git a/src/libsmack-tests/libsmack-test.cpp b/src/libsmack-tests/libsmack-test.cpp
deleted file mode 100644 (file)
index ccbb00e..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Copyright (c) 2014 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.
- *    You may obtain a copy of the License at
- *
- *        http://www.apache.org/licenses/LICENSE-2.0
- *
- *    Unless required by applicable law or agreed to in writing, software
- *    distributed under the License is distributed on an "AS IS" BASIS,
- *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *    See the License for the specific language governing permissions and
- *    limitations under the License.
- */
-/*
- * @file        libprivilege-test.cpp
- * @author      Pawel Polawski (p.polawski@samsung.com)
- * @version     1.0
- * @brief       libsmack test runer
- */
-#include <dpl/test/test_runner.h>
-
-int main (int argc, char *argv[])
-{
-    int status = DPL::Test::TestRunnerSingleton::Instance().ExecTestRunner(argc, argv);
-    return status;
-}
-
diff --git a/src/libsmack-tests/test_cases.cpp b/src/libsmack-tests/test_cases.cpp
deleted file mode 100644 (file)
index 6f87dd3..0000000
+++ /dev/null
@@ -1,1727 +0,0 @@
-/*
- * Copyright (c) 2012 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.
- *    You may obtain a copy of the License at
- *
- *        http://www.apache.org/licenses/LICENSE-2.0
- *
- *    Unless required by applicable law or agreed to in writing, software
- *    distributed under the License is distributed on an "AS IS" BASIS,
- *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *    See the License for the specific language governing permissions and
- *    limitations under the License.
- */
-
-/*
- * @file        test_cases.cpp
- * @author      Pawel Polawski (p.polawski@samsung.com)
- * @author      Jan Olszak (j.olszak@samsung.com)
- * @author      Zofia Abramowska (z.abramowska@samsung.com)
- * @version     1.0
- * @brief       libsmack test runner
- */
-
-#include <string>
-#include <sstream>
-#include <fcntl.h>
-#include <unistd.h>
-#include <dpl/test/test_runner.h>
-#include <dpl/test/test_runner_multiprocess.h>
-#include <dpl/log/log.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/smack.h>
-#include <sys/xattr.h>
-#include <sys/socket.h>
-#include <sys/un.h>
-#include <sys/file.h>
-#include <sys/wait.h>
-#include "tests_common.h"
-#include <access_provider.h>
-#include <fs_label_manager.h>
-#include "memory.h"
-
-const char* const TEST_SUBJECT = "test_subject";
-const char* const TEST_OBJECT = "test_object";
-const char* const TEST_OBJECT_2 = "test_object_2";
-
-const std::string testDir = "/tmp/";
-const std::vector<std::string> accessesBasic = { "r", "w", "x", "wx", "rx", "rw", "rwx", "rwxat" };
-
-//This one define is required for sockaddr_un initialization
-#define SOCK_PATH "/tmp/test-smack-socket"
-
-RUNNER_TEST_GROUP_INIT(libsmack)
-/**
- * Helper method to reset privileges at the begginning of tests.
- */
-void clean_up()
-{
-    smack_revoke_subject(TEST_SUBJECT);
-}
-
-/**
- * Checking if subject has any access to object
- */
-bool checkNoAccesses(const char *subject, const char *object)
-{
-    int result;
-
-    for(const auto &perm : std::vector<std::string> {"r", "w", "a","t", "l"}) {
-        result = smack_have_access(subject, object, perm.c_str());
-        if (result == 1) {
-            return false;
-        }
-    }
-    return true;
-}
-
-void removeAccessesAll()
-{
-    for(int i = 1; i <=3; i++)
-        //smack_revoke_subject will fail, when subject does not exist in kernel
-        //as this function is called at test beginning we cannot check return value
-        smack_revoke_subject(("test_subject_0" + std::to_string(i)).c_str());
-}
-
-/**
- * Add a new access with smack_accesses_add_modify()
- */
-RUNNER_TEST_SMACK(smack_accesses_add_modify_test_1){
-    int result;
-
-    clean_up();
-
-    struct smack_accesses *rules = nullptr;
-    RUNNER_ASSERT(smack_accesses_new(&rules) == 0);
-    SmackAccessesPtr rules_ptr(rules);
-
-    // THE TEST
-    result = smack_accesses_add_modify(rules,TEST_SUBJECT, TEST_OBJECT,"xr","");
-    RUNNER_ASSERT_MSG(result == 0, "Unable to add modify by empty rules");
-    RUNNER_ASSERT_MSG(smack_accesses_apply(rules_ptr.get()) == 0, "Unable to apply rules");
-
-    result = smack_have_access(TEST_SUBJECT, TEST_OBJECT,"xr");
-    RUNNER_ASSERT_MSG(result == 1, "Rule modified (added 'xr'), but no change made.");
-
-    // CLEAN UP
-    clean_up();
-}
-
-
-/**
- * Test if rules are applied in the right order, and modification works.
- */
-RUNNER_TEST_SMACK(smack_accesses_add_modify_test_2){
-    int result;
-    struct smack_accesses *rules = nullptr;
-    RUNNER_ASSERT(smack_accesses_new(&rules) == 0);
-    SmackAccessesPtr rules_ptr(rules);
-
-    clean_up();
-
-    // THE TEST
-    result = smack_accesses_add_modify(rules_ptr.get(),TEST_SUBJECT, TEST_OBJECT,"r","");
-    RUNNER_ASSERT_MSG(result == 0, "Unable to modify rule.");
-
-    result = smack_accesses_add_modify(rules_ptr.get(),TEST_SUBJECT, TEST_OBJECT,"","r");
-    RUNNER_ASSERT_MSG(result == 0, "Unable to modify rule.");
-
-    RUNNER_ASSERT_MSG(smack_accesses_apply(rules_ptr.get()) == 0, "Unable to apply rules");
-    RUNNER_ASSERT_MSG(smack_have_access(TEST_SUBJECT, TEST_OBJECT,"r") == 0,
-            "Modification didn't work");
-
-    // CLEAN UP
-    clean_up();
-}
-
-
-/**
- * Test if rules are applied in the right order, and modification works.
- * Using different smack_accesses list to add and delete.
- */
-RUNNER_TEST_SMACK(smack_accesses_add_modify_test_3){
-    int result;
-    struct smack_accesses *rules = nullptr;
-    RUNNER_ASSERT(smack_accesses_new(&rules) == 0);
-    SmackAccessesPtr rules_ptr(rules);
-
-    clean_up();
-
-    // THE TEST
-    // Add r privilage
-    result = smack_accesses_add_modify(rules_ptr.get(),TEST_SUBJECT, TEST_OBJECT,"r","");
-    RUNNER_ASSERT_MSG(result == 0, "Unable to modify rule.");
-    RUNNER_ASSERT_MSG(smack_accesses_apply(rules_ptr.get()) == 0, "Unable to apply rules");
-    RUNNER_ASSERT_MSG(smack_have_access(TEST_SUBJECT, TEST_OBJECT,"r") == 1,
-            "Adding privileges didn't work");
-
-    // Revoke r privilege
-    rules_ptr.release();
-    RUNNER_ASSERT(smack_accesses_new(&rules) == 0);
-    rules_ptr.reset(rules);
-    result = smack_accesses_add_modify(rules_ptr.get(),TEST_SUBJECT, TEST_OBJECT,"","r");
-    RUNNER_ASSERT_MSG(result == 0, "Unable to modify rule.");
-    RUNNER_ASSERT_MSG(smack_accesses_apply(rules_ptr.get()) == 0, "Unable to apply rules");
-
-    result = smack_have_access(TEST_SUBJECT, TEST_OBJECT,"r");
-    RUNNER_ASSERT_MSG(result == 0, "Modification didn't work, rule has still 'r' privileges.");
-
-    // CLEAN UP
-    clean_up();
-}
-
-/**
- * Add a list of privileges and then revoke just ONE of them.
- */
-RUNNER_TEST_SMACK(smack_accesses_add_modify_test_4){
-    int result;
-    struct smack_accesses *rules = nullptr;
-    RUNNER_ASSERT(smack_accesses_new(&rules) == 0);
-    SmackAccessesPtr rules_ptr(rules);
-
-    clean_up();
-
-    // THE TEST
-    result = smack_accesses_add_modify(rules_ptr.get(),TEST_SUBJECT, TEST_OBJECT,"rwxat","");
-    RUNNER_ASSERT_MSG(result == 0, "Unable to modify rule.");
-    RUNNER_ASSERT_MSG(smack_accesses_apply(rules_ptr.get()) == 0, "Unable to apply rules");
-
-    result = smack_accesses_add_modify(rules_ptr.get(),TEST_SUBJECT, TEST_OBJECT,"","r");
-    RUNNER_ASSERT_MSG(result == 0, "Unable to modify rule.");
-    RUNNER_ASSERT_MSG(smack_accesses_apply(rules_ptr.get()) == 0, "Unable to apply rules");
-
-    result = smack_have_access(TEST_SUBJECT, TEST_OBJECT,"awxt");
-    RUNNER_ASSERT_MSG(result == 1, "Modification didn't work. Rule should have 'awxt' privileges.");
-    result = smack_have_access(TEST_SUBJECT, TEST_OBJECT,"r");
-    RUNNER_ASSERT_MSG(result != 1, "Modification didn't work. Rule should NOT have 'r' privilege.");
-
-    // CLEAN UP
-    clean_up();
-}
-
-/**
- * Add a list of privileges and then revoke just ONE of them.
- * Without applying privileges in between those actions.
- */
-RUNNER_TEST_SMACK(smack_accesses_add_modify_test_5){
-    int result;
-    struct smack_accesses *rules = nullptr;
-    RUNNER_ASSERT(smack_accesses_new(&rules) == 0);
-    SmackAccessesPtr rules_ptr(rules);
-
-    clean_up();
-
-    // THE TEST
-    result = smack_accesses_add_modify(rules_ptr.get(),TEST_SUBJECT, TEST_OBJECT,"rwxat","");
-    RUNNER_ASSERT_MSG(result == 0, "Unable to modify rule.");
-
-    result = smack_accesses_add_modify(rules_ptr.get(),TEST_SUBJECT, TEST_OBJECT,"","r");
-    RUNNER_ASSERT_MSG(result == 0, "Unable to modify rule.");
-    RUNNER_ASSERT_MSG(smack_accesses_apply(rules_ptr.get()) == 0, "Unable to apply rules");
-
-    result = smack_have_access(TEST_SUBJECT, TEST_OBJECT,"awxt");
-    RUNNER_ASSERT_MSG(result == 1, "Modification didn't work. Rule should have 'awxt' privileges.");
-    result = smack_have_access(TEST_SUBJECT, TEST_OBJECT,"r");
-    RUNNER_ASSERT_MSG(result != 1, "Modification didn't work. Rule should NOT have 'r' privilege.");
-
-    // CLEAN UP
-    clean_up();
-}
-
-
-/**
- * Add a list of privileges and then revoke just TWO of them.
- */
-RUNNER_TEST_SMACK(smack_accesses_add_modify_test_6){
-    int result;
-    struct smack_accesses *rules = nullptr;
-    RUNNER_ASSERT(smack_accesses_new(&rules) == 0);
-    SmackAccessesPtr rules_ptr(rules);
-
-    clean_up();
-
-    // THE TEST
-    result = smack_accesses_add_modify(rules_ptr.get(),TEST_SUBJECT, TEST_OBJECT,"rwt","");
-    RUNNER_ASSERT_MSG(result == 0, "Unable to modify rule.");
-    RUNNER_ASSERT_MSG(smack_accesses_apply(rules_ptr.get()) == 0, "Unable to apply rules");
-
-    result = smack_accesses_add_modify(rules_ptr.get(),TEST_SUBJECT, TEST_OBJECT,"ax","rt");
-    RUNNER_ASSERT_MSG(result == 0, "Unable to modify rule.");
-    RUNNER_ASSERT_MSG(smack_accesses_apply(rules_ptr.get()) == 0, "Unable to apply rules");
-
-    result = smack_have_access(TEST_SUBJECT, TEST_OBJECT,"wax");
-    RUNNER_ASSERT_MSG(result == 1, "Modification didn't work. Rule should have 'wax' privileges.");
-    result = smack_have_access(TEST_SUBJECT, TEST_OBJECT,"r");
-    RUNNER_ASSERT_MSG(result != 1, "Modification didn't work. Rule should NOT have 'r' privilege.");
-
-    // CLEAN UP
-    clean_up();
-}
-
-/**
- * Run smack_accesses_add_modify with the same accesses_add and accesses_del.
- */
-RUNNER_TEST_SMACK(smack_accesses_add_modify_test_7){
-    unsigned int i;
-    int result;
-
-    struct smack_accesses *rules = nullptr;
-
-    for (i = 0; i < accessesBasic.size(); ++i) {
-        RUNNER_ASSERT(smack_accesses_new(&rules) == 0);
-        SmackAccessesPtr rules_ptr(rules);
-
-        result = smack_accesses_add_modify(rules_ptr.get(),TEST_SUBJECT, TEST_OBJECT,
-                accessesBasic[i].c_str(), accessesBasic[i].c_str());
-        RUNNER_ASSERT_MSG(result == 0, "Unable to modify accesses instance");
-        RUNNER_ASSERT_MSG(smack_accesses_apply(rules_ptr.get()) == 0, "Unable to apply rules");
-
-        RUNNER_ASSERT_MSG(checkNoAccesses(TEST_SUBJECT, TEST_OBJECT),
-            " Error while checking smack access. Accesses exist.");
-
-        // CLEAN UP
-        clean_up();
-    }
-}
-
-/**
- * Revoke subject with previously added rules and revoke it again.
- */
-RUNNER_TEST_SMACK(smack_revoke_subject_test_1){
-    unsigned int i;
-    int result;
-
-    struct smack_accesses *rules = nullptr;
-
-    for (i = 0; i < accessesBasic.size(); ++i) {
-        // Creating and adding rules with TEST_OBJECT and TEST_OBJECT_2
-        RUNNER_ASSERT(smack_accesses_new(&rules) == 0);
-        SmackAccessesPtr rules_ptr(rules);
-
-        result = smack_accesses_add_modify(rules_ptr.get(),TEST_SUBJECT, TEST_OBJECT,
-                accessesBasic[i].c_str(),"");
-        result = smack_accesses_add_modify(rules_ptr.get(),TEST_SUBJECT, TEST_OBJECT_2,
-                accessesBasic[i].c_str(),"");
-        RUNNER_ASSERT_MSG(result == 0, "Unable to modify accesses instance");
-        RUNNER_ASSERT_MSG(smack_accesses_apply(rules_ptr.get()) == 0, "Unable to apply rules");
-        result = smack_have_access(TEST_SUBJECT, TEST_OBJECT,accessesBasic[i].c_str());
-        RUNNER_ASSERT_MSG(result == 1, "Modification didn't work. "
-                "Rule " << accessesBasic[i].c_str() << " does not exist.");
-        result = smack_have_access(TEST_SUBJECT, TEST_OBJECT_2,accessesBasic[i].c_str());
-        RUNNER_ASSERT_MSG(result == 1, "Modification didn't work. "
-                "Rule " << accessesBasic[i].c_str() << " does not exist.");
-
-        // Revoking subject
-        result = smack_revoke_subject(TEST_SUBJECT);
-        RUNNER_ASSERT_MSG(result == 0, "Revoking subject didn't work.");
-
-        RUNNER_ASSERT_MSG(checkNoAccesses(TEST_SUBJECT, TEST_OBJECT),
-            " Revoke didn't work. Accesses exist.");
-        RUNNER_ASSERT_MSG(checkNoAccesses(TEST_SUBJECT, TEST_OBJECT_2),
-            " Revoke didn't work. Accesses exist.");
-
-
-        // Revoking subject again
-        result = smack_revoke_subject(TEST_SUBJECT);
-        RUNNER_ASSERT_MSG(result == 0, "Revoking subject didn't work.");
-
-        RUNNER_ASSERT_MSG(checkNoAccesses(TEST_SUBJECT, TEST_OBJECT),
-            " Revoke didn't work. Accesses exist.");
-        RUNNER_ASSERT_MSG(checkNoAccesses(TEST_SUBJECT, TEST_OBJECT_2),
-            " Revoke didn't work. Accesses exist.");
-
-    }
-}
-
-/**
- * Clearing accesses
- */
-RUNNER_TEST_SMACK(smack_accesses_clear_test_1){
-    unsigned int i;
-    int result;
-
-    struct smack_accesses *rules = nullptr;
-
-    for (i = 0; i < accessesBasic.size(); ++i) {
-        // Creating and adding rules with TEST_OBJECT and TEST_OBJECT_2
-        RUNNER_ASSERT(smack_accesses_new(&rules) == 0);
-        SmackAccessesPtr rules_ptr(rules);
-        result = smack_accesses_add(rules_ptr.get(),TEST_SUBJECT, TEST_OBJECT,
-                accessesBasic[i].c_str());
-        RUNNER_ASSERT_MSG(result == 0, "Unable to modify accesses instance");
-        result = smack_accesses_add(rules_ptr.get(),TEST_SUBJECT, TEST_OBJECT_2,
-                accessesBasic[i].c_str());
-        RUNNER_ASSERT_MSG(result == 0, "Unable to modify accesses instance");
-        RUNNER_ASSERT_MSG(smack_accesses_apply(rules_ptr.get()) == 0, "Unable to apply rules");
-
-        result = smack_have_access(TEST_SUBJECT, TEST_OBJECT,accessesBasic[i].c_str());
-        RUNNER_ASSERT_MSG(result == 1, "Modification didn't work. Rule "
-                << accessesBasic[i].c_str() << " does not exist.");
-        result = smack_have_access(TEST_SUBJECT, TEST_OBJECT_2,accessesBasic[i].c_str());
-        RUNNER_ASSERT_MSG(result == 1, "Modification didn't work. Rule "
-                << accessesBasic[i].c_str() << " does not exist.");
-
-        // Creating and clearing rules with TEST_OBJECT
-        rules_ptr.release();
-        RUNNER_ASSERT(smack_accesses_new(&rules) == 0);
-        rules_ptr.reset(rules);
-        result = smack_accesses_add(rules_ptr.get(),TEST_SUBJECT, TEST_OBJECT,
-                accessesBasic[i].c_str());
-        RUNNER_ASSERT_MSG(result == 0, "Unable to modify accesses instance");
-        result = smack_accesses_clear(rules_ptr.get());
-        RUNNER_ASSERT_MSG(result == 0, "Clearing rules didn't work.");
-
-        result = smack_have_access(TEST_SUBJECT, TEST_OBJECT,accessesBasic[i].c_str());
-        RUNNER_ASSERT_MSG(result == 0, "Clearing rules didn't work. Rule "
-                << accessesBasic[i].c_str() << " does exist.");
-        result = smack_have_access(TEST_SUBJECT, TEST_OBJECT_2,accessesBasic[i].c_str());
-        RUNNER_ASSERT_MSG(result == 1, "Clearing rules didn't work. Rule "
-                << accessesBasic[i].c_str() << " does not exist.");
-
-        // Creating and clearing rules with TEST_OBJECT
-        rules_ptr.release();
-        RUNNER_ASSERT(smack_accesses_new(&rules) == 0);
-        rules_ptr.reset(rules);
-
-        result = smack_accesses_add(rules_ptr.get(),TEST_SUBJECT, TEST_OBJECT_2,
-                accessesBasic[i].c_str());
-        RUNNER_ASSERT_MSG(result == 0, "Unable to modify accesses instance");
-        result = smack_accesses_clear(rules_ptr.get());
-        RUNNER_ASSERT_MSG(result == 0, "Clearing rules didn't work.");
-
-        RUNNER_ASSERT_MSG(checkNoAccesses(TEST_SUBJECT, TEST_OBJECT),
-            " Clear didn't work. Accesses exist.");
-        RUNNER_ASSERT_MSG(checkNoAccesses(TEST_SUBJECT, TEST_OBJECT_2),
-            " Clear didn't work. Accesses exist.");
-    }
-}
-
-RUNNER_TEST(smack01_storing_and_restoring_rules)
-{
-    /*
-     * author: Pawel Polawski
-     * test: smack_accesses_new, smack_accesses_add, smack_accesses_add_modify, smack_accesses_add_from_file,
-     *       smack_accesses_free, smack_accesses_save
-     * description: This test case will create structure holding SMACK rules and add new one to it. Next rules will be
-     *              stored and restored from file.
-     * expect: Rules created and stored in file should be identical to predefined template.
-     */
-
-    struct smack_accesses *rules = nullptr;        //rules prepared in this test case
-    struct smack_accesses *import_test = nullptr;  //rules imported from file
-
-    int result;             //result of each operation to be tested by RUNNER_ASSERT
-    int fd, tmp, sample;    //file descripptors for save / restore rules tests
-
-    //int smack_accesses_new(struct smack_accesses **accesses);
-    RUNNER_ASSERT(smack_accesses_new(&rules) == 0);
-    SmackAccessesPtr rules_ptr(rules);
-    RUNNER_ASSERT(smack_accesses_new(&import_test) == 0);
-    SmackAccessesPtr import_ptr(import_test);
-
-    //opening files
-    fd = open("/tmp/smack01_rules", O_RDWR | O_CREAT | O_TRUNC, 0644);  //for export prepared rules
-    RUNNER_ASSERT_ERRNO_MSG(fd >= 0, "Unable to create /tmp/smack01_rules");
-    FdUniquePtr fd_ptr(&fd);
-    tmp = open("/tmp/smack01_tmp", O_RDWR | O_CREAT | O_TRUNC, 0644);   //for import rules exported before
-    RUNNER_ASSERT_ERRNO_MSG(fd >= 0, "Unable to create /tmp/smack01_tmp");
-    FdUniquePtr tmp_ptr(&tmp);
-    sample = open("/etc/smack/test_smack_rules", O_RDONLY, 0644);             //reference preinstalled rules
-    RUNNER_ASSERT_ERRNO_MSG(sample >= 0, "Unable to open /etc/smack/test_smack_rules");
-    FdUniquePtr sample_ptr(&sample);
-
-    result = smack_accesses_add(rules_ptr.get(), "writer", "book", "rw");
-    RUNNER_ASSERT_MSG(result == 0, "Unable to add smack rules");
-    result = smack_accesses_add(rules_ptr.get(), "reader", "book", "wx");
-    RUNNER_ASSERT_MSG(result == 0, "Unable to add smack rules");
-
-    result = smack_accesses_add_modify(rules_ptr.get(), "reader", "book", "r", "wx");
-    RUNNER_ASSERT_MSG(0 == result, "Unable to modify smack rules");
-
-    result = smack_accesses_save(rules_ptr.get(), fd);
-    RUNNER_ASSERT_MSG(0 == result, "Unable to save smack_accesses instance in file");
-
-    result = lseek(fd, 0, SEEK_SET);
-    RUNNER_ASSERT_ERRNO_MSG(result == 0, "lseek() error");
-    result = smack_accesses_add_from_file(import_ptr.get(), fd);
-    RUNNER_ASSERT_MSG(result == 0, "Unable to import rules from file");
-
-    result = smack_accesses_save(import_ptr.get(), tmp);
-    RUNNER_ASSERT_MSG(result == 0, "Unable to save smack_accesses instance in file");
-
-    //comparing rules saved in file, restored from it and stored one more time
-    result = files_compare(fd, tmp);
-    RUNNER_ASSERT_MSG(result == 0, "No match in stored and restored rules");
-
-    //comparing rules stored in file with reference preinstalled rules
-    result = files_compare(tmp, sample);
-    RUNNER_ASSERT_MSG(result == 0, "No match in stored rules and pattern file");
-}
-
-RUNNER_TEST_SMACK(smack02_aplying_rules_into_kernel)
-{
-    /*
-     * author: Pawel Polawski
-     * test: smack_accesses_apply, smack_have_access, smack_revoke_subject, smack_accesses_clear, smack_accesses_new,
-     *       smack_accesses_add, smack_accesses_free
-     * description: In this test case aplying rules to kernel will be tested. After that function for test
-     *              accesses will be used.
-     * expect: In case of correct rules access should be granted.
-     */
-
-    //CAP_MAC_ADMIN needed for process to be able to change rules in kernel (apllying, removing)
-
-    struct smack_accesses *rules = nullptr;        //rules prepared in this test case
-    int result;                                 //for storing functions results
-
-    RUNNER_ASSERT(smack_accesses_new(&rules) == 0);
-    SmackAccessesPtr rules_ptr(rules);
-
-    //adding test rules to struct
-    result = smack_accesses_add(rules_ptr.get(), "writer", "book", "rwx");
-    RUNNER_ASSERT_MSG(result == 0, "Unable to add smack rules");
-    result = smack_accesses_add(rules_ptr.get(), "reader", "book", "r");
-    RUNNER_ASSERT_MSG(result == 0, "Unable to add smack rules");
-    result = smack_accesses_add(rules_ptr.get(), "spy", "book", "rwx");
-    RUNNER_ASSERT_MSG(result == 0, "Unable to add smack rules");
-
-    result = smack_accesses_apply(rules_ptr.get());       //applying rules to kernel
-    RUNNER_ASSERT_MSG(result == 0, "Unable to apply rules into kernel");
-
-    //should have access - rule exist
-    result = smack_have_access("spy", "book", "rwx");
-    RUNNER_ASSERT_MSG(result == 1, "Error while checking Smack access");
-    //should have no access - wrong rule, should be "r" only
-    result = smack_have_access("reader", "book", "rwx");
-    RUNNER_ASSERT_MSG(result == 0, "Error while checking Smack access");
-    //should have no access - rule not exist
-    result = smack_have_access("s02badsubjectlabel", "book", "rwx");
-    RUNNER_ASSERT_MSG(result == 0, "Error while checking Smack access");
-
-    //this subject do not exist in kernel rules
-    result = smack_revoke_subject("s02nonexistinglabel");
-    RUNNER_ASSERT_MSG(result == 0, "Error in removing not existing subject from kernel");
-    result = smack_revoke_subject("spy");       //this subject exist in kernel rules
-    RUNNER_ASSERT_MSG(result == 0, "Error in removing existing subject from kernel");
-
-    //testing access after revoke_subject() from kernel
-    result = smack_have_access("spy", "book", "rwx");
-    //now spy should have no access
-    RUNNER_ASSERT_MSG(result == 0, "Error in acces aplied to kernel");
-
-    //for create new rule as a consequence of use accesses_clear() below
-    result = smack_accesses_add(rules_ptr.get(), "s02subjectlabel", "book", "rwx");
-    RUNNER_ASSERT_MSG(result == 0, "Unable to add smack rules");
-
-    //"spy" removed before by using smack_revoke_subject()
-    result = smack_accesses_clear(rules_ptr.get());
-    RUNNER_ASSERT_MSG(result == 0, "Error in clearing rules in kernel");
-
-    //testing acces after acces_clear()
-    result = smack_have_access("writer", "book", "rwx");
-    //now writer also should have no access
-    RUNNER_ASSERT_MSG(result == 0, "Error in acces aplied to kernel");
-
-}
-
-//pairs of rules for test with mixed cases, different length and mixed order
-std::vector< std::vector<std::string> > correct_rules = {
-    { "reader1",  "-",                "------" },
-    { "reader2",  "--------",         "------" },
-    { "reader3",  "RwXaTl",           "rwxatl" },
-    { "reader4",  "RrrXXXXTTT",       "r-x-t-" },
-    { "reader5",  "-r-w-a-t-",        "rw-at-" },
-    { "reader6",  "",                 "------" },
-    { "reader7",  "xa--Rt---W--L",    "rwxatl" },
-};
-
-RUNNER_TEST_SMACK(smack03_mixed_rule_string_add)
-{
-    /*
-     * author: Pawel Polawski
-     * test: smack_have_access, smack_accesses_new, smack_accesses_add, smack_accesses_apply, smack_accesses_free
-     * description: In thist test case rules based on mixed string are added to kernel.
-     *              Strings are presented above and contains lower / upper case alpha, numbers and special signs.
-     * expect: Rules should be parsed correct and aplied to kernel.
-     */
-
-    //In thist test case mixed string are used as rules applied to kernel, next they are
-    //readed and compared with correct form of rules
-
-    struct smack_accesses *rules = nullptr;        //rules prepared in this test case
-    int result;                                 //for storing functions results
-    int expected;
-
-    RUNNER_ASSERT(smack_accesses_new(&rules) == 0);
-    SmackAccessesPtr rules_ptr(rules);
-
-    //adding test rules with mixed string
-    for (auto rule=correct_rules.begin(); rule != correct_rules.end(); ++rule) {
-        //using mixed rules from table
-        result = smack_accesses_add(rules_ptr.get(),
-                                    (*rule)[0].c_str(),
-                                    "book",
-                                    (*rule)[1].c_str());
-        RUNNER_ASSERT_MSG(result == 0, "Unable to add smack rules");
-    }
-
-    //clearing
-    //FIXME: Using clear() here can cover error in accesses_apply() function
-    //result = smack_accesses_clear(rules);
-    //RUNNER_ASSERT_MSG(result == 0, "Error in clearing rules in kernel");
-
-    //applying rules to kernel
-    result = smack_accesses_apply(rules_ptr.get());
-    RUNNER_ASSERT_MSG(result == 0, "Unable to apply rules into kernel");
-
-    //checking accesses using normal rules
-    for (auto rule=correct_rules.begin(); rule != correct_rules.end(); ++rule) {
-        if ((*rule)[2] == "------")
-            expected = 0;
-        else
-            expected = 1;
-        //using normal rules from table
-        result = smack_have_access((*rule)[0].c_str(),
-                                   "book",
-                                   (*rule)[2].c_str());
-        RUNNER_ASSERT_MSG(result == expected, "Error while checking Smack access");
-    }
-}
-
-RUNNER_TEST_SMACK(smack04_mixed_rule_string_have_access)
-{
-    /*
-     * author: Pawel Polawski
-     * test: smack_have_access
-     * description: In this test case we testing aplied before SMACK rules and comparing them using mixed strings.
-     * expect: Subjects should have accesses to the objects.
-     */
-
-    //In this test case we checking previous aplied rules but for compare mixed strings are used
-
-    int result;
-    int expected;
-
-    //rules were added in previous RUNNER_TEST section
-    //checking accesses using mixed rules
-    for (auto rule=correct_rules.begin(); rule != correct_rules.end(); ++rule) {
-        if ((*rule)[2] == "------")
-            expected = 0;
-        else
-            expected = 1;
-        //using mixed rules from table
-        result = smack_have_access((*rule)[0].c_str(),
-                                   "book",
-                                   (*rule)[1].c_str());
-        RUNNER_ASSERT_MSG(result == expected, "Error while checking Smack access");
-    }
-}
-
-//RUNNER_TEST(smackXX_accesses_add_modify)
-//{
-//IDEAS FOR TESTS
-// - what if we want to apply rule that is already in kernel?
-// - tests for smack_accesses_add_modify() + smack_have_access() (check if add_modify sets the proper rule)
-// - smack_accesses_add_modify("subject", "object", "rwx", "rwx") should create empty rule
-//}
-
-RUNNER_TEST_SMACK(smack05_self_label)
-{
-    /*
-     * author: Pawel Polawski
-     * test: smack_set_label_for_self, smack_new_label_from_self
-     * description: In this test case process test it own default label. Next label is changed
-     *              and tested one more time if change was successfull.
-     * expect: Proces should have default "-" label and can change it to the oter one.
-     */
-
-    //In this test case process will manipulate it own label
-
-    char *label = nullptr;
-    int result;
-    int fd;
-
-    const int B_SIZE = 8;
-    char buff[B_SIZE];
-
-    const char *def_rule = "_";
-
-    result = smack_new_label_from_self(&label);
-    RUNNER_ASSERT_MSG(result >= 0, "Error in getting self label");
-    //comparing this label with default one "_"
-    result = strcmp(label, def_rule);
-    free(label);
-    RUNNER_ASSERT_MSG(result == 0, "Wrong default process label");
-
-    //comparing this rule with received from /proc/self/attr/current
-    fd = open("/proc/self/attr/current", O_RDONLY, 0644);
-    RUNNER_ASSERT_ERRNO_MSG(fd >= 0, "Unable to open /proc/self/attr/current");
-    FdUniquePtr fd_ptr(&fd);
-    result = read(fd, buff, B_SIZE);
-    RUNNER_ASSERT_ERRNO_MSG(result >= 0, "Error in reading from file /proc/self/attr/current");
-    result = strncmp(buff, def_rule, result);
-    RUNNER_ASSERT_MSG(result == 0, "Wrong default process rule");
-
-    //now time for setting labels:
-
-    result = smack_set_label_for_self("cola");
-    RUNNER_ASSERT_MSG(result == 0, "Error in setting self label");
-
-    //checking new label using smack function
-    result = smack_new_label_from_self(&label);
-    RUNNER_ASSERT_MSG(result >= 0, "Error in getting self label");
-    result = strcmp(label, "cola");
-    free(label);
-    RUNNER_ASSERT_MSG(result == 0, "Wrong process label");
-
-    //checking new label using /proc/self/attr/current
-    result = lseek(fd, 0, SEEK_SET);    //going to the file beginning
-    RUNNER_ASSERT_ERRNO_MSG(result == 0, "lseek() error");
-    result = read(fd, buff, B_SIZE);
-    RUNNER_ASSERT_ERRNO_MSG(result >= 0, "Error in reading from file /proc/self/attr/current");
-    result = strncmp(buff, "cola", result);
-    RUNNER_ASSERT_MSG(result == 0, "Proces rule in /proc/self/attr/current other than set");
-}
-
-RUNNER_TEST_SMACK(smack06_setlabel_getlabel_test_0)
-{
-    RUNNER_IGNORED_MSG("Upstream does not support label removal yet");
-    const std::string fsLabel = "smack06_setlabel_getlabel_test_0";
-    const std::string fsPath = std::string("/tmp/") + fsLabel;
-
-    const std::string filePath = "file";
-
-    FsLabelManager fs(fsPath, fsLabel);
-    fs.createFile(filePath);
-
-    // reset labels first time
-    fs.testSmackClearLabels(filePath);
-
-    // reset labels second time
-    fs.testSmackClearLabels(filePath);
-}
-
-RUNNER_TEST_SMACK(smack06_setlabel_getlabel_test_1)
-{
-    const std::string fsLabel = "smack06_setlabel_getlabel_test_1";
-    const std::string fsPath = std::string("/tmp/") + fsLabel;
-
-    const char* testLabelAccess = "access";
-    const char* testLabelExec = "exec";
-    const std::string filePath = "file";
-
-    FsLabelManager fs(fsPath, fsLabel);
-    fs.createFile(filePath);
-
-    // set and get labels first time
-    fs.testSmackSetLabel(filePath, testLabelAccess, SMACK_LABEL_ACCESS);
-    fs.testSmackGetLabel(filePath, testLabelAccess, SMACK_LABEL_ACCESS);
-    fs.testSmackSetLabel(filePath, testLabelExec, SMACK_LABEL_EXEC);
-    fs.testSmackGetLabel(filePath, testLabelExec, SMACK_LABEL_EXEC);
-
-    fs.testSmackSetLabel(filePath, testLabelAccess, SMACK_LABEL_ACCESS);
-    fs.testSmackGetLabel(filePath, testLabelAccess, SMACK_LABEL_ACCESS);
-    fs.testSmackSetLabel(filePath, testLabelExec, SMACK_LABEL_EXEC);
-    fs.testSmackGetLabel(filePath, testLabelExec, SMACK_LABEL_EXEC);
-
-    // set and get same labels second time
-    fs.testSmackSetLabel(filePath, testLabelAccess, SMACK_LABEL_ACCESS);
-    fs.testSmackGetLabel(filePath, testLabelAccess, SMACK_LABEL_ACCESS);
-    fs.testSmackSetLabel(filePath, testLabelExec, SMACK_LABEL_EXEC);
-    fs.testSmackGetLabel(filePath, testLabelExec, SMACK_LABEL_EXEC);
-
-    fs.testSmackSetLabel(filePath, testLabelAccess, SMACK_LABEL_ACCESS);
-    fs.testSmackGetLabel(filePath, testLabelAccess, SMACK_LABEL_ACCESS);
-    fs.testSmackSetLabel(filePath, testLabelExec, SMACK_LABEL_EXEC);
-    fs.testSmackGetLabel(filePath, testLabelExec, SMACK_LABEL_EXEC);
-}
-
-RUNNER_TEST_SMACK(smack06_setlabel_getlabel_test_2)
-{
-    RUNNER_IGNORED_MSG("Upstream does not support label removal yet");
-    const std::string fsLabel = "smack06_setlabel_getlabel_test_2";
-    const std::string fsPath = std::string("/tmp/") + fsLabel;
-
-    const char* testLabelAccess = "access";
-    const char* testLabelExec = "exec";
-    const std::string filePath = "file";
-    const std::string linkPath = "link";
-
-    FsLabelManager fs(fsPath, fsLabel);
-    fs.createFile(filePath);
-    fs.createLink(linkPath, filePath);
-
-    // set and get labels for file to which link points
-    fs.testSmackSetLabel(linkPath, testLabelAccess, SMACK_LABEL_ACCESS);
-    fs.testSmackSetLabel(linkPath, testLabelExec, SMACK_LABEL_EXEC);
-    fs.testSmackGetLabel(filePath, testLabelAccess, SMACK_LABEL_ACCESS);
-    fs.testSmackGetLabel(filePath, testLabelExec, SMACK_LABEL_EXEC);
-    fs.testSmackGetLabel(linkPath, testLabelAccess, SMACK_LABEL_ACCESS);
-    fs.testSmackGetLabel(linkPath, testLabelExec, SMACK_LABEL_EXEC);
-
-    // link labels should not be changed
-    fs.testSmackLGetLabel(linkPath, nullptr, SMACK_LABEL_ACCESS);
-    fs.testSmackLGetLabel(linkPath, nullptr, SMACK_LABEL_EXEC);
-}
-
-RUNNER_TEST_SMACK(smack06_lsetlabel_lgetlabel_test_1)
-{
-    const std::string fsLabel = "smack06_lsetlabel_lgetlabel_test_1";
-    const std::string fsPath = std::string("/tmp/") + fsLabel;
-
-    const char* testLabelAccess = "fileAccess";
-    const char* testLabelExec = "fileExec";
-    const char* testLinkLabelAccess = "linkAccess";
-    const char* testLinkLabelExec = "linkExec";
-    const std::string filePath = "file";
-    const std::string linkPath = "link";
-
-    FsLabelManager fs(fsPath, fsLabel);
-    fs.createFile(filePath);
-    fs.createLink(linkPath, filePath);
-
-    // set different labels for link and file
-    fs.testSmackSetLabel(filePath, testLabelAccess, SMACK_LABEL_ACCESS);
-    fs.testSmackSetLabel(filePath, testLabelExec, SMACK_LABEL_EXEC);
-    fs.testSmackLSetLabel(linkPath, testLinkLabelAccess, SMACK_LABEL_ACCESS);
-    fs.testSmackLSetLabel(linkPath, testLinkLabelExec, SMACK_LABEL_EXEC);
-
-    // get those labels
-    fs.testSmackGetLabel(filePath, testLabelAccess, SMACK_LABEL_ACCESS);
-    fs.testSmackGetLabel(filePath, testLabelExec, SMACK_LABEL_EXEC);
-    fs.testSmackLGetLabel(linkPath, testLinkLabelAccess, SMACK_LABEL_ACCESS);
-    fs.testSmackLGetLabel(linkPath, testLinkLabelExec, SMACK_LABEL_EXEC);
-}
-
-RUNNER_TEST_SMACK(smack06_fsetlabel_fgetlabel_test_1)
-{
-    const std::string fsLabel = "smack06_fsetlabel_fgetlabel_test_1";
-    const std::string fsPath = std::string("/tmp/") + fsLabel;
-
-    const char* testLabelAccess = "access";
-    const char* testLabelExec = "exec";
-    const std::string filePath = "file";
-
-    FsLabelManager fs(fsPath, fsLabel);
-    fs.createFile(filePath);
-
-    // set and get labels for fd
-    fs.testSmackFSetLabel(filePath, testLabelAccess, SMACK_LABEL_ACCESS);
-    fs.testSmackFSetLabel(filePath, testLabelExec, SMACK_LABEL_EXEC);
-    fs.testSmackFGetLabel(filePath, testLabelAccess, SMACK_LABEL_ACCESS);
-    fs.testSmackFGetLabel(filePath, testLabelExec, SMACK_LABEL_EXEC);
-}
-
-RUNNER_TEST_SMACK(smack10_adding_removing_rules)
-{
-    unsigned int i;
-    int result;
-
-    struct smack_accesses *rules = nullptr;
-
-    for (i = 0; i < accessesBasic.size(); ++i)
-    {
-        // Creating rules
-        RUNNER_ASSERT(smack_accesses_new(&rules) == 0);
-        SmackAccessesPtr rules_ptr(rules);
-
-        // Adding accesses
-        result = smack_accesses_add(rules_ptr.get(), TEST_SUBJECT, TEST_OBJECT, accessesBasic[i].c_str());
-        RUNNER_ASSERT_MSG(result == 0, "Unable to add modify rulesBasic. Result: " << result);
-
-        // Applying rules
-        result = smack_accesses_apply(rules_ptr.get());
-        RUNNER_ASSERT_MSG(result == 0, "Error while applying accesses. Result: " << result);
-
-        // Checking if accesses were created
-        result = smack_have_access(TEST_SUBJECT, TEST_OBJECT, accessesBasic[i].c_str());
-        RUNNER_ASSERT_MSG(result == 1,
-            " Error while checking smack access. Result: " << result);
-
-        // Deleting all rules
-        clean_up();
-    }
-
-    for (i = 0; i < 3; ++i)
-    {
-        // --- Creating rules (r or w or x)
-        RUNNER_ASSERT(smack_accesses_new(&rules) == 0);
-        SmackAccessesPtr rules_ptr(rules);
-
-        // Adding accesses
-        result = smack_accesses_add(rules_ptr.get(), TEST_SUBJECT, TEST_OBJECT, accessesBasic[i].c_str());
-        RUNNER_ASSERT_MSG(result == 0, "Unable to add rulesBasic. Result: " << result);
-
-        // Applying rules
-        result = smack_accesses_apply(rules_ptr.get());
-        RUNNER_ASSERT_MSG(result == 0, "Error while applying accesses. Result: " << result);
-        // Checking if accesses were created
-        result = smack_have_access(TEST_SUBJECT, TEST_OBJECT, accessesBasic[i].c_str());
-        RUNNER_ASSERT_MSG(result == 1,
-            " Error while checking smack access. Result: " << result);
-
-        // Checking if wrong accesses were not created
-        result = smack_have_access(TEST_SUBJECT, TEST_OBJECT, accessesBasic[i + 3].c_str());
-        RUNNER_ASSERT_MSG(result == 0,
-            " Error while checking smack access. Result: " << result);
-
-        // --- Modifying accesses (r for wx or w for rx or x for rw)
-        result = smack_accesses_add_modify(rules_ptr.get(),TEST_SUBJECT, TEST_OBJECT,
-                accessesBasic[i + 3].c_str(),accessesBasic[i].c_str());
-        RUNNER_ASSERT_MSG(result == 0, "Unable to add modify rulesBasic. Result: " << result);
-
-        // Applying rules
-        result = smack_accesses_apply(rules_ptr.get());
-        RUNNER_ASSERT_MSG(result == 0, "Error while applying accesses. Result: " << result);
-
-        // Checking if accesses were created
-        result = smack_have_access(TEST_SUBJECT, TEST_OBJECT, accessesBasic[i + 3].c_str());
-        RUNNER_ASSERT_MSG(result == 1,
-            " Error while checking smack access. Result: " << result);
-
-        // Checking if wrong accesses were not created
-        result = smack_have_access(TEST_SUBJECT, TEST_OBJECT, accessesBasic[i].c_str());
-        RUNNER_ASSERT_MSG(result == 0,
-            " Error while checking smack access. Result: " << result);
-
-        rules_ptr.release();
-        // --- Creating complementary rules (r or w or x)
-        RUNNER_ASSERT(smack_accesses_new(&rules) == 0);
-        rules_ptr.reset(rules);
-
-        // Adding accesses
-        result = smack_accesses_add(rules_ptr.get(), TEST_SUBJECT, TEST_OBJECT,
-                accessesBasic[i].c_str());
-        RUNNER_ASSERT_MSG(result == 0, "Unable to add rulesBasic. Result: " << result);
-
-        // Checking if accesses were created
-        result = smack_have_access(TEST_SUBJECT, TEST_OBJECT, accessesBasic[i + 3].c_str());
-        RUNNER_ASSERT_MSG(result == 1,
-            " Error while checking smack access. Result: " << result);
-
-        // Applying rules
-        result = smack_accesses_apply(rules_ptr.get());
-        RUNNER_ASSERT_MSG(result == 0, "Error while applying accesses. Result: " << result);
-
-        // Checking if accesses were created
-        result = smack_have_access(TEST_SUBJECT, TEST_OBJECT, accessesBasic[i].c_str());
-        RUNNER_ASSERT_MSG(result == 1,
-            " Error while checking smack access. Result: " << result);
-
-        // --- Modifying accesses (adding rwx and removing r or w or x)
-        result = smack_accesses_add_modify(rules_ptr.get(),TEST_SUBJECT, TEST_OBJECT,"rwx",
-                accessesBasic[i].c_str());
-        RUNNER_ASSERT_MSG(result == 0, "Unable to add modify rulesBasic. Result: " << result);
-
-        // Applying rules
-        result = smack_accesses_apply(rules_ptr.get());
-        RUNNER_ASSERT_MSG(result == 0, "Error while applying accesses. Result: " << result);
-
-        // Checking if accesses were created
-        result = smack_have_access(TEST_SUBJECT, TEST_OBJECT, accessesBasic[i + 3].c_str());
-        RUNNER_ASSERT_MSG(result == 1,
-            " Error while checking smack access. Result: " << result);
-
-        // Checking if wrong accesses were not created
-        result = smack_have_access(TEST_SUBJECT, TEST_OBJECT, accessesBasic[i].c_str());
-        RUNNER_ASSERT_MSG(result == 0,
-            " Error while checking smack access. Result: " << result);
-
-        // --- Adding crossing accesses (rx or rw or wx)
-        result = smack_accesses_add_modify(rules_ptr.get(),TEST_SUBJECT, TEST_OBJECT,
-                accessesBasic[3 + ((i + 1) % 3)].c_str(),"");
-        RUNNER_ASSERT_MSG(result == 0, "Unable to add modify rulesBasic. Result: " << result);
-
-        // Applying rules
-        result = smack_accesses_apply(rules_ptr.get());
-        RUNNER_ASSERT_MSG(result == 0, "Error while applying accesses. Result: " << result);
-
-        // Checking if accesses were created
-        result = smack_have_access(TEST_SUBJECT, TEST_OBJECT,
-                accessesBasic[3 + ((i + 1) % 3)].c_str());
-        RUNNER_ASSERT_MSG(result == 1,
-            " Error while checking smack access. Result: " << result);
-
-        result = smack_have_access(TEST_SUBJECT, TEST_OBJECT, "rwx");
-        RUNNER_ASSERT_MSG(result == 1,
-            " Error while checking smack access. Result: " << result);
-
-        // Deleting all rules
-        result = smack_accesses_add_modify(rules,TEST_SUBJECT, TEST_OBJECT,"","rwx");
-        RUNNER_ASSERT_MSG(result == 0, "Unable to add modify rulesBasic. Result: " << result);
-
-        result = smack_accesses_apply(rules_ptr.get());
-        RUNNER_ASSERT_MSG(result == 0, "Error while checking smack access. Result: " << result);
-
-        // Deleting all rules
-        clean_up();
-    }
-}
-
-RUNNER_TEST_SMACK(smack11_saving_loading_rules)
-{
-    int result;
-    int fd;
-
-    struct smack_accesses *rules = nullptr;
-
-    // Pre-cleanup
-    removeAccessesAll();
-
-    RUNNER_ASSERT(smack_accesses_new(&rules) == 0);
-    SmackAccessesPtr rules_ptr(rules);
-
-    // Loading file with rwxat rules - test_smack_rules_full
-    fd = open("/etc/smack/test_smack_rules_full", O_RDONLY, 0644);
-    RUNNER_ASSERT_ERRNO_MSG(fd >= 0, "Unable to open /etc/smack/test_smack_rules_full");
-
-    // Adding rules from file
-    result = smack_accesses_add_from_file(rules_ptr.get(), fd);
-    close(fd);
-    RUNNER_ASSERT_MSG(result == 0, "Error importing accesses from file");
-
-    // Applying rules
-    result = smack_accesses_apply(rules_ptr.get());
-    RUNNER_ASSERT_MSG(result == 0, "Error while applying accesses. Result: " << result);
-
-    // Checking rules
-    result = smack_have_access("test_subject_01", "test_object_02", "rwxat");
-    RUNNER_ASSERT_MSG(result == 1,
-        " Error while checking smack accesses.");
-    result = smack_have_access("test_subject_01", "test_object_03", "rwxat");
-    RUNNER_ASSERT_MSG(result == 1,
-        " Error while checking smack accesses.");
-    result = smack_have_access("test_subject_02", "test_object_01", "rwxat");
-    RUNNER_ASSERT_MSG(result == 1,
-        " Error while checking smack accesses.");
-    result = smack_have_access("test_subject_02", "test_object_02", "rwxat");
-    RUNNER_ASSERT_MSG(result == 1,
-        " Error while checking smack accesses.");
-    result = smack_have_access("test_subject_02", "test_object_03", "rwxat");
-    RUNNER_ASSERT_MSG(result == 1,
-        " Error while checking smack accesses.");
-    result = smack_have_access("test_subject_03", "test_object_01", "rwxat");
-    RUNNER_ASSERT_MSG(result == 1,
-        " Error while checking smack accesses.");
-    result = smack_have_access("test_subject_03", "test_object_02", "rwxat");
-    RUNNER_ASSERT_MSG(result == 1,
-        " Error while checking smack accesses.");
-    result = smack_have_access("test_subject_03", "test_object_03", "rwxat");
-    RUNNER_ASSERT_MSG(result == 1,
-        " Error while checking smack accesses.");
-
-    // Removing rules
-    removeAccessesAll();
-
-    // Creating rules
-    rules_ptr.release();
-    RUNNER_ASSERT(smack_accesses_new(&rules) == 0);
-    rules_ptr.reset(rules);
-
-    // Loading file with partial wrong rules - test_smack_rules2
-    fd = open("/etc/smack/test_smack_rules2", O_RDONLY, 0644);
-    RUNNER_ASSERT_ERRNO_MSG(fd >= 0, "Unable to open /etc/smack/test_smack_rules2");
-
-    // Adding rules from file
-    result = smack_accesses_add_from_file(rules_ptr.get(), fd);
-    close(fd);
-    RUNNER_ASSERT_MSG(result == 0, "Error importing accesses from file");
-
-    // Applying rules
-    result = smack_accesses_apply(rules_ptr.get());
-    RUNNER_ASSERT_MSG(result == 0, "Error while applying accesses. Result: " << result);
-
-    // Checking rules
-    RUNNER_ASSERT_MSG(checkNoAccesses("test_subject_01", "test_object_01"),
-        " Error while checking smack access loaded from /etc/smack/test_smack_rules2. Accesses exist.");
-    result = smack_have_access("test_subject_01", "test_object_02", "rwatl");
-    RUNNER_ASSERT_MSG(result == 1,
-        " Error while checking smack access loaded from /etc/smack/test_smack_rules2. Result: " << result );
-    result = smack_have_access("test_subject_01", "test_object_03", "wat");
-    RUNNER_ASSERT_MSG(result == 1,
-        " Error while checking smack access loaded from /etc/smack/test_smack_rules2. Result: " << result );
-    RUNNER_ASSERT_MSG(checkNoAccesses("test_subject_02", "test_object_01"),
-        " Error while checking smack access loaded from /etc/smack/test_smack_rules2. Accesses exist.");
-    result = smack_have_access("test_subject_02", "test_object_02", "wa-lt");
-    RUNNER_ASSERT_MSG(result == 1,
-        " Error while checking smack access loaded from /etc/smack/test_smack_rules2. Result: " << result );
-    result = smack_have_access("test_subject_02", "test_object_03", "wr");
-    RUNNER_ASSERT_MSG(result == 1,
-        " Error while checking smack access loaded from /etc/smack/test_smack_rules2. Result: " << result );
-    result = smack_have_access("test_subject_03", "test_object_01", "a");
-    RUNNER_ASSERT_MSG(result == 1,
-        " Error while checking smack access loaded from /etc/smack/test_smack_rules2. Result: " << result );
-    result = smack_have_access("test_subject_03", "test_object_02", "rwat");
-    RUNNER_ASSERT_MSG(result == 1,
-        " Error while checking smack access loaded from /etc/smack/test_smack_rules2. Result: " << result );
-    result = smack_have_access("test_subject_03", "test_object_03", "w---l-");
-    RUNNER_ASSERT_MSG(result == 1,
-        " Error while checking smack access loaded from /etc/smack/test_smack_rules2. Result: " << result );
-
-    // Removing rules
-    removeAccessesAll();
-
-    // Creating rules
-    rules_ptr.release();
-    RUNNER_ASSERT(smack_accesses_new(&rules) == 0);
-    rules_ptr.reset(rules);
-
-    // Loading file with partial wrong rules - test_smack_rules3
-    fd = open("/etc/smack/test_smack_rules3", O_RDONLY, 0644);
-    RUNNER_ASSERT_ERRNO_MSG(fd >= 0, "Unable to open /etc/smack/test_smack_rules3");
-
-    // Adding rules from file
-    result = smack_accesses_add_from_file(rules_ptr.get(), fd);
-    close(fd);
-    RUNNER_ASSERT_MSG(result != 0, "Accesses were loaded from file");
-
-    // Removing rules
-    removeAccessesAll();
-
-    // Creating rules
-    rules_ptr.release();
-    RUNNER_ASSERT(smack_accesses_new(&rules) == 0);
-    rules_ptr.reset(rules);
-
-    // Loading file with partial wrong rules - test_smack_rules4
-    fd = open("/etc/smack/test_smack_rules4", O_RDONLY, 0644);
-    RUNNER_ASSERT_ERRNO_MSG(fd >= 0, "Unable to open /etc/smack/test_smack_rules4");
-
-    // Adding rules from file
-    result = smack_accesses_add_from_file(rules_ptr.get(), fd);
-    close(fd);
-    RUNNER_ASSERT_MSG(result != 0, "Accesses were loaded from file");
-
-    // Removing rules
-    removeAccessesAll();
-}
-
-//int smack_new_label_from_socket(int fd, char **label);
-
-
-static void smack_set_another_label_for_self(void)
-{
-    static int number = time(nullptr);
-
-    number++;
-    std::string smack_label("s" + std::to_string(number));
-
-    int result = smack_set_label_for_self(smack_label.c_str());
-    RUNNER_ASSERT_MSG(result == 0, "smack_set_label_for_self(" << smack_label << ") failed");
-}
-
-static void smack_unix_sock_server(int sock)
-{
-    int fd, result;
-    char *label;
-
-    alarm(2);
-    fd = accept(sock, nullptr, nullptr);
-    alarm(0);
-    RUNNER_ASSERT_ERRNO(fd >= 0);
-    FdUniquePtr fd_ptr(&fd);
-
-    result = smack_new_label_from_self(&label);
-    RUNNER_ASSERT_MSG(result >= 0, "smack_new_label_from_self() failed");
-    CStringPtr label_ptr(label);
-    result = write(fd, label, strlen(label));
-    RUNNER_ASSERT_ERRNO_MSG(result == (int)strlen(label), "write() failed");
-
-}
-
-RUNNER_CHILD_TEST_SMACK(smack09_new_label_from_socket)
-{
-    int pid;
-    struct sockaddr_un sockaddr = {AF_UNIX, SOCK_PATH};
-    unlink(SOCK_PATH);
-    smack_set_another_label_for_self();
-    pid = fork();
-    RUNNER_ASSERT_ERRNO_MSG(pid >= 0, "Fork failed");
-    if (!pid) { /* child process, server */
-        int sock, result;
-
-
-        sock = socket(AF_UNIX, SOCK_STREAM, 0);
-        RUNNER_ASSERT_ERRNO_MSG(sock >= 0, "socket failed");
-        SockUniquePtr sock_ptr(&sock);
-        result = bind(sock, (struct sockaddr*) &sockaddr, sizeof(struct sockaddr_un));
-        RUNNER_ASSERT_ERRNO_MSG(result == 0, "bind failed");
-        result = listen(sock, 1);
-        RUNNER_ASSERT_ERRNO_MSG(result == 0, "listen failed");
-        smack_unix_sock_server(sock);
-
-        pid = fork();
-        RUNNER_ASSERT_ERRNO_MSG(pid >= 0, "Fork failed");
-        /*  Test if socket label was unaffected by fork() */
-        smack_unix_sock_server(sock);
-        if (!pid) {
-            usleep (100);
-            smack_set_another_label_for_self();
-            smack_unix_sock_server(sock);
-        }
-
-        exit(0);
-    } else { /* parent process, client */
-        sleep(1); /* Give server some time to setup listening socket */
-        for (int i = 0; i < 4; ++i) {
-            int sock, result;
-            char smack_label1[SMACK_LABEL_LEN + 1];
-            char *smack_label2;
-
-            sock = socket(AF_UNIX, SOCK_STREAM, 0);
-            RUNNER_ASSERT_ERRNO_MSG(sock >= 0, "socket failed");
-            SockUniquePtr sock_ptr(&sock);
-            result = connect(sock, (struct sockaddr*) &sockaddr, sizeof(struct sockaddr_un));
-            RUNNER_ASSERT_ERRNO_MSG(result == 0, "connect failed");
-            alarm(2);
-            result = read(sock, smack_label1, SMACK_LABEL_LEN);
-            alarm(0);
-            RUNNER_ASSERT_ERRNO_MSG(result >= 0, "read failed");
-            smack_label1[result] = '\0';
-            result = smack_new_label_from_socket(sock, &smack_label2);
-            SmackLabelPtr label2_ptr(smack_label2);
-            RUNNER_ASSERT_MSG(result >= 0, "smack_label_from_socket failed");
-            result = strcmp(smack_label1, label2_ptr.get());
-            if (i < 3)
-                RUNNER_ASSERT_MSG(result == 0, "smack labels differ: '" << smack_label1
-                        << "' != '" << smack_label2 << "' i == " << i);
-            else
-                RUNNER_ASSERT_MSG(result != 0, "smack labels do not differ: '" << smack_label1
-                        << "' != '" << smack_label2 << "' i == " << i);
-        }
-    }
-}
-
-void createFileWithLabel(const std::string &filePath, const std::string &fileLabel)
-{
-    //create temporary file and set label for it
-    mode_t systemMask;
-
-    unlink(filePath.c_str());
-    //allow to create file with 777 rights
-    systemMask = umask(0000);
-    int fd = open(filePath.c_str(), O_RDWR | O_CREAT, S_IRWXU | S_IRWXG | S_IRWXO);
-    //restore system mask
-    umask(systemMask);
-    RUNNER_ASSERT_ERRNO_MSG(fd > -1, "Unable to create file for tests");
-
-    //for descriptor protection
-    FdUniquePtr fd_ptr(&fd);
-
-    //change owner and group to user APP
-    int ret = chown(filePath.c_str(), APP_UID, APP_GID);
-    RUNNER_ASSERT_ERRNO_MSG(ret == 0, "Unable to change file owner");
-
-    //set smack label on file
-    ret = smack_setlabel(filePath.c_str(), fileLabel.c_str(), SMACK_LABEL_ACCESS);
-    RUNNER_ASSERT_MSG(ret == 0, "Unable to set label for file: " << ret);
-
-    char *label = nullptr;
-    ret = smack_getlabel(filePath.c_str(), &label, SMACK_LABEL_ACCESS);
-    RUNNER_ASSERT_MSG(ret == 0, "Unable to get label from file");
-    std::string label_str(label ? label : "");
-    free(label);
-    RUNNER_ASSERT_MSG(label_str == fileLabel, "File label not match set label");
-}
-
-void prepareEnvironment(const std::string &subject, const std::string &object, const std::string &access)
-{
-    const std::string ruleAll = "x";
-
-    SecurityServer::AccessProvider provider(subject);
-    provider.addObjectRule("User", ruleAll);
-    provider.addObjectRule(object, access);
-    provider.applyAndSwithToUser(APP_UID, APP_GID);
-}
-
-//- Add "l" rule to system
-//
-//Should be able to add "l" rule to system
-RUNNER_CHILD_TEST_SMACK(smack13_0_checking_laccess_mode_enabled_on_device)
-{
-    std::string selfLabel = "smack13_0";
-    std::string filename = "smack13_0_file";
-
-    //function inside checks if rule exist after add it
-    SecurityServer::AccessProvider provider(selfLabel);
-    provider.addObjectRule(filename, "l");
-    provider.apply();
-
-    int ret = smack_have_access(selfLabel.c_str(), filename.c_str(), "l");
-    RUNNER_ASSERT_MSG(ret == 1, "Error in adding laccess rule - l");
-}
-
-//- Create file
-//- Set label for file and self
-//- Drop privileges
-//
-//Should have no access due to missing SMACK rule
-RUNNER_CHILD_TEST_SMACK(smack13_1_checking_laccess_mode)
-{
-    std::string selfLabel = "smack13_1";
-    std::string filename = "smack13_1_file";
-    std::string filePath = testDir + filename;
-
-    createFileWithLabel(filePath, filename);
-    int fd = open(filePath.c_str(), O_RDWR, 0);
-    FdUniquePtr fd_ptr(&fd);
-
-    SecurityServer::AccessProvider provider(selfLabel);
-    provider.applyAndSwithToUser(APP_UID, APP_GID);
-
-    int ret = flock(fd, LOCK_EX | LOCK_NB);
-    RUNNER_ASSERT_ERRNO_MSG(ret < 0, "Error, able to lock file");
-    ret = flock(fd, LOCK_UN | LOCK_NB);
-    RUNNER_ASSERT_ERRNO_MSG(ret < 0, "Error, able to lock file");
-    ret = flock(fd, LOCK_SH | LOCK_NB);
-    RUNNER_ASSERT_ERRNO_MSG(ret < 0, "Error, able to lock file");
-}
-
-//- Create file
-//- Set label for file and self
-//- Add SMACK rule "l"
-//- Drop privileges
-//
-//Should be able to lock file even without "w" rule
-RUNNER_CHILD_TEST_SMACK(smack13_2_checking_laccess_mode_with_l_rule)
-{
-    std::string selfLabel = "smack13_2";
-    std::string filename = "smack13_2_file";
-    std::string filePath = testDir + filename;
-
-    createFileWithLabel(filePath, filename);
-    int fd = open(filePath.c_str(), O_RDWR, 0);
-    FdUniquePtr fd_ptr(&fd);
-
-    prepareEnvironment(selfLabel, filename, "l");
-
-    int ret = flock(fd, LOCK_EX | LOCK_NB);
-    RUNNER_ASSERT_ERRNO_MSG(ret == 0, "Error, unable to exclusive lock file");
-    ret = flock(fd, LOCK_UN | LOCK_NB);
-    RUNNER_ASSERT_ERRNO_MSG(ret == 0, "Error, unable to unlock file");
-    ret = flock(fd, LOCK_SH | LOCK_NB);
-    RUNNER_ASSERT_ERRNO_MSG(ret == 0, "Error, unable to shared lock file");
-}
-
-//- Create file
-//- Set label for file and self
-//- Add SMACK rule "w"
-//- Drop privileges
-//
-//Should be able to lock file even without "l" rule
-RUNNER_CHILD_TEST_SMACK(smack13_3_checking_laccess_mode_with_w_rule)
-{
-    std::string selfLabel = "smack13_3";
-    std::string filename = "smack13_3_file";
-    std::string filePath = testDir + filename;
-
-    createFileWithLabel(filePath, filename);
-    int fd = open(filePath.c_str(), O_RDWR, 0);
-    FdUniquePtr fd_ptr(&fd);
-
-    prepareEnvironment(selfLabel, filename, "w");
-
-    int ret = flock(fd, LOCK_EX | LOCK_NB);
-    RUNNER_ASSERT_ERRNO_MSG(ret == 0, "Error, unable to exclusive lock file");
-    ret = flock(fd, LOCK_UN | LOCK_NB);
-    RUNNER_ASSERT_ERRNO_MSG(ret == 0, "Error, unable to unlock file");
-    ret = flock(fd, LOCK_SH | LOCK_NB);
-    RUNNER_ASSERT_ERRNO_MSG(ret == 0, "Error, unable to shared lock file");
-}
-
-//- Create file
-//- Set label for file and self
-//- Add SMACK rule "rw"
-//- Drop privileges
-//- Lock file (shared lock)
-//- Spawn child process
-//- Child tries to lock file (shared)
-//
-//Child should be able to lock file due to shared lock
-RUNNER_CHILD_TEST_SMACK(smack13_4_0_checking_laccess_mode_w_rule_child)
-{
-    std::string selfLabel = "smack13_4_0";
-    std::string filename = "smack13_4_0_file";
-    std::string filePath = testDir + filename;
-
-    createFileWithLabel(filePath, filename);
-    int fd = open(filePath.c_str(), O_RDWR);
-    FdUniquePtr fd_ptr(&fd);
-    int ret = flock(fd, LOCK_SH | LOCK_NB);
-    RUNNER_ASSERT_ERRNO_MSG(ret == 0, "Error, unable to shared lock file");
-
-    pid_t pid = fork();
-    if (pid == 0) {
-        //child process
-        prepareEnvironment(selfLabel, filename, "rw");
-
-        int child_fd = open(filePath.c_str(), O_RDWR);
-        RUNNER_ASSERT_ERRNO_MSG(child_fd > -1, "Unable to open created file");
-        //for descriptor protection
-        FdUniquePtr child_fd_ptr(&child_fd);
-
-        ret = flock(child_fd, LOCK_SH | LOCK_NB);
-        RUNNER_ASSERT_ERRNO_MSG(ret == 0, "Error, unable to lock file with shared lock");
-    }
-}
-
-//- Create file
-//- Set label for file and self
-//- Add SMACK rule "l"
-//- Drop privileges
-//- Lock file (shared lock)
-//- Spawn child process
-//- Child tries to lock file (shared)
-//
-//Child should be able to lock file due to shared lock
-RUNNER_CHILD_TEST_SMACK(smack13_4_1_checking_laccess_mode_l_rule_child)
-{
-    std::string selfLabel = "smack13_4_1";
-    std::string filename = "smack13_4_1_file";
-    std::string filePath = testDir + filename;
-
-    createFileWithLabel(filePath, filename);
-    int fd = open(filePath.c_str(), O_RDWR);
-    FdUniquePtr fd_str(&fd);
-    int ret = flock(fd, LOCK_SH | LOCK_NB);
-    RUNNER_ASSERT_ERRNO_MSG(ret == 0, "Error, unable to shared lock file");
-
-    pid_t pid = fork();
-    if (pid == 0) {
-        //child process
-        //"r" is only for open in O_RDONLY mode
-        prepareEnvironment(selfLabel, filename, "rl");
-
-        int child_fd = open(filePath.c_str(), O_RDONLY, 0);
-        RUNNER_ASSERT_ERRNO_MSG(child_fd > -1, "Unable to open created file");
-        //for descriptor protection
-        FdUniquePtr child_fd_ptr(&child_fd);
-
-        ret = flock(child_fd, LOCK_SH | LOCK_NB);
-        RUNNER_ASSERT_ERRNO_MSG(ret == 0, "Error, unable to lock file with shared lock");
-    }
-}
-
-//- Create file
-//- Set label for file and self
-//- Add SMACK rule "rw"
-//- Drop privileges
-//- Lock file (exclusive lock)
-//- Spawn child process
-//- Child tries to lock file (exclusive / shared)
-//
-//Child should not be able to lock file due to exclusive lock
-RUNNER_CHILD_TEST_SMACK(smack13_4_2_checking_laccess_mode_w_rule_child)
-{
-    std::string selfLabel = "smack13_4_2";
-    std::string filename = "smack13_4_2_file";
-    std::string filePath = testDir + filename;
-
-    createFileWithLabel(filePath, filename);
-    int fd = open(filePath.c_str(), O_RDWR);
-    FdUniquePtr fd_ptr(&fd);
-    int ret = flock(fd, LOCK_EX | LOCK_NB);
-    RUNNER_ASSERT_ERRNO_MSG(ret == 0, "Error, unable to exclusive lock file");
-
-    pid_t pid = fork();
-    if (pid == 0) {
-        //child process
-        prepareEnvironment(selfLabel, filename, "rw");
-
-        int child_fd = open(filePath.c_str(), O_RDWR, 0);
-        RUNNER_ASSERT_ERRNO_MSG(child_fd > -1, "Unable to open created file");
-        //for descriptor protection
-        FdUniquePtr child_fd_ptr(&child_fd);
-
-        ret = flock(child_fd, LOCK_EX | LOCK_NB);
-        RUNNER_ASSERT_ERRNO_MSG(ret < 0, "Error, able to lock file with exclusive lock");
-    }
-}
-
-//- Create file
-//- Set label for file and self
-//- Add SMACK rule "l"
-//- Drop privileges
-//- Lock file (exclusive lock)
-//- Spawn child process
-//- Child tries to lock file (exclusive / shared)
-//
-//Child should not be able to lock file due to exclusive lock
-RUNNER_CHILD_TEST_SMACK(smack13_4_3_checking_laccess_mode_l_rule_child)
-{
-    std::string selfLabel = "smack13_4_3";
-    std::string filename = "smack13_4_3_file";
-    std::string filePath = testDir + filename;
-
-    createFileWithLabel(filePath, filename);
-    int fd = open(filePath.c_str(), O_RDWR, 0);
-    FdUniquePtr fd_ptr(&fd);
-    int ret = flock(fd, LOCK_EX | LOCK_NB);
-    RUNNER_ASSERT_ERRNO_MSG(ret == 0, "Error, unable to exclusive lock file");
-
-    pid_t pid = fork();
-    if (pid == 0) {
-        //child process
-        //"r" is only for open in O_RDONLY mode
-        prepareEnvironment(selfLabel, filename, "rl");
-
-        int child_fd = open(filePath.c_str(), O_RDONLY, 0);
-        RUNNER_ASSERT_ERRNO_MSG(child_fd > -1, "Unable to open created file");
-        //for descriptor protection
-        FdUniquePtr child_fd_ptr(&child_fd);
-
-        ret = flock(child_fd, LOCK_EX | LOCK_NB);
-        RUNNER_ASSERT_ERRNO_MSG(ret < 0, "Error, able to lock file with eclusive lock");
-    }
-}
-
-
-/////////////////////////////////////////
-//////NOSMACK ENVIRONMENT TESTS//////////
-/////////////////////////////////////////
-
-/**
- * NOSMACK version of smack02 test. Functions, that should return error instead of success:
- * - smack_accesses_apply
- * - smack_have_access
- * - smack_revoke_subject
- * - smack_acceesses_clear
- *
- * Tests smack03, smack04, smack10, smack_accesses_clear, smack_revoke_subject all use functions
- * tested in smack02 test. Results from those functions (smack_have_access, smack_accesses_apply,
- * smack_accesses_clear, smack_revoke_subject) would be the same as in this test. Tests mentioned
- * above doesn't make much sense on NOSMACK environment when test smack02 exists and passes
- * correctly, thus those tests are are not implemented.
- */
-RUNNER_TEST_NOSMACK(smack02_aplying_rules_into_kernel_nosmack)
-{
-
-    smack_accesses *rules = nullptr;
-    int result;
-
-    //init rules
-    RUNNER_ASSERT(smack_accesses_new(&rules) == 0);
-    //pass rules to unique_ptr
-    SmackAccessesPtr rules_ptr(rules);
-
-    //adding test rules to struct (same as SMACK version of smack02 test)
-    result = smack_accesses_add(rules_ptr.get(), "writer", "book", "rwx");
-    RUNNER_ASSERT_MSG(result == 0, "Unable to add smack rules");
-    result = smack_accesses_add(rules_ptr.get(), "reader", "book", "r");
-    RUNNER_ASSERT_MSG(result == 0, "Unable to add smack rules");
-    result = smack_accesses_add(rules_ptr.get(), "spy", "book", "rwx");
-    RUNNER_ASSERT_MSG(result == 0, "Unable to add smack rules");
-
-    //applying rules to kernel (should fail)
-    result = smack_accesses_apply(rules_ptr.get());
-    RUNNER_ASSERT_MSG(result == -1, "Unable to apply rules into kernel");
-
-    //calls from SMACK version of this test - all should fail because of SMACK being turned off
-    result = smack_have_access("spy", "book", "rwx");
-    RUNNER_ASSERT_MSG(result == -1, "smack_have_access should return error (SMACK is off)");
-    result = smack_have_access("reader", "book", "rwx");
-    RUNNER_ASSERT_MSG(result == -1, "smack_have_access should return error (SMACK is off)");
-    result = smack_have_access("s02badsubjectlabel", "book", "rwx");
-    RUNNER_ASSERT_MSG(result == -1, "smack_have_access should return error (SMACK is off)");
-
-    //testing subject revoking - should return error (no accesses applied = no subjects to revoke)
-    result = smack_revoke_subject("s02nonexistinglabel");
-    RUNNER_ASSERT_MSG(result == -1, "smack_revoke_subject error - subject doesn't exist.");
-    result = smack_revoke_subject("spy");
-    RUNNER_ASSERT_MSG(result == -1, "smack_revoke_subject error - subject doesn't exist.");
-
-    //after revoking smack_have_access still should return error
-    result = smack_have_access("spy", "book", "rwx");
-    RUNNER_ASSERT_MSG(result == -1, "smack_have_access should return error (SMACK is off).");
-
-    result = smack_accesses_add(rules_ptr.get(), "s02subjectlabel", "book", "rwx");
-    RUNNER_ASSERT_MSG(result == 0, "Unable to add smack rules");
-
-    //smack_accesses_clear should return error aswell
-    result = smack_accesses_clear(rules_ptr.get());
-    RUNNER_ASSERT_MSG(result == -1, "Clearing rules should return error - no SMACK on system.");
-
-    result = smack_have_access("writer", "book", "rwx");
-    RUNNER_ASSERT_MSG(result == -1, "smack_have_access should return error (SMACK is off).");
-}
-
-/**
- * NOSMACK version of smack11 test. Tests functions:
- * - smack_accesses_add_from_file
- *
- * Since other SMACK functions were tested in smack02 test, the only function needed to be checked
- * is applying rules loaded from file.
- */
-RUNNER_TEST_NOSMACK(smack03_saving_loading_rules_nosmack)
-{
-    int result;
-    int fd;
-
-    smack_accesses* tmp = nullptr;
-
-    RUNNER_ASSERT(smack_accesses_new(&tmp) == 0);
-    SmackAccessesPtr rules(tmp);
-
-    //open file with rules
-    fd = open("/etc/smack/test_smack_rules_full", O_RDONLY, 0644);
-    RUNNER_ASSERT_ERRNO_MSG(fd >= 0, "Unable to open /etc/smack/test_smack_rules_full");
-
-    //load accesses from file
-    result = smack_accesses_add_from_file(rules.get(), fd);
-    close(fd);
-    RUNNER_ASSERT_MSG(result == 0, "Error while importing accesses from file. Result: " << result);
-}
-
-/**
- * NOSMACK version of smack05 test. Tests if functions getting, or
- * setting self label work correctly (that is, return error).
- */
-RUNNER_TEST_NOSMACK(smack04_self_label_nosmack)
-{
-    char* label = nullptr;
-    int result;
-    int fd;
-
-    char buff[SMACK_LABEL_LEN+1];
-
-    //smack_new_label_from_self should fail
-    result = smack_new_label_from_self(&label);
-    RUNNER_ASSERT_MSG(result == -1, "new_label_from_self should return error (SMACK is off).");
-    RUNNER_ASSERT_MSG(label == nullptr, "new_label_from_self shouldn't allocate memory to label.");
-    //We don't need to remember about freeing label - smack_new_label_from_self must return nullptr
-    //label if it's working properly.
-
-    // /proc/self/attr/current shouldn't keep any rules inside
-    fd = open("/proc/self/attr/current", O_RDONLY, 0644);   //file exists, so it should open
-    RUNNER_ASSERT_ERRNO_MSG(fd >= 0, "/proc/self/attr/current failed to open");
-    FdUniquePtr fd_ptr(&fd);
-
-    result = read(fd, buff, SMACK_LABEL_LEN);   //however reading it should return error
-    RUNNER_ASSERT_ERRNO_MSG(result < 0, "Reading /proc/self/attr/current should return error");
-
-    //setting label for self should fail
-    result = smack_set_label_for_self("s04testlabel");
-    RUNNER_ASSERT_MSG(result == -1, "set_label_for_self should return error (SMACK is off).");
-
-    //getting previously set label should also fail
-    result = smack_new_label_from_self(&label);
-    RUNNER_ASSERT_MSG(result == -1, "new_label_from_self should return error (SMACK is off).");
-    RUNNER_ASSERT_MSG(label == nullptr, "new_label_from_self shouldn't allocate memory to label.");
-
-    // /proc/self/attr/current still shouldn't keep any rules inside
-    result = lseek(fd, 0, SEEK_SET);    //going to the file beginning
-    RUNNER_ASSERT_ERRNO_MSG(result == 0, "lseek() error");
-
-    result = read(fd, buff, SMACK_LABEL_LEN);   //however it should return error
-    RUNNER_ASSERT_ERRNO_MSG(result < 0, "Reading /proc/self/attr/current should return error");
-}
-
-/**
- * NOSMACK version of smack_accesses_add_modify_x tests.
- *
- * Because all smack_accesses_add_modify tests are basically the same (all use smack_accesses_apply
- * and smack_have_access, which return -1 when SMACK is turned off), it makes much more sense to
- * write one test which will create rules using smack_accesses_add_modify and then check if
- * smack_accesses_apply and smack_have_access indeed return -1 when SMACK is turned off.
- */
-RUNNER_TEST_NOSMACK(smack05_accesses_add_modify_nosmack)
-{
-    int result;
-    smack_accesses* rules = nullptr;
-
-    RUNNER_ASSERT(smack_accesses_new(&rules) == 0);
-
-    SmackAccessesPtr rules_ptr(rules);
-
-    //Not doing clean_up() every RUNNER_ASSERT_MSG - what clean_up does is just a creation of new
-    //rule struct and removal of currenctly added and applied rules. clean_up() must be done only
-    //after smack_accesses_apply().
-    result = smack_accesses_add_modify(rules_ptr.get(), TEST_SUBJECT, TEST_OBJECT, "rwx", "");
-    RUNNER_ASSERT_MSG(result == 0, "Unable to modify rule. Result: " << result);
-
-    result = smack_accesses_add_modify(rules_ptr.get(), TEST_SUBJECT, TEST_OBJECT, "rwx", "");
-    RUNNER_ASSERT_MSG(result == 0, "Unable to modify rule. Result: " << result);
-
-    result = smack_accesses_apply(rules_ptr.get());
-    RUNNER_ASSERT_MSG(result == -1,
-            "smack_accesses_apply should return error (SMACK is off). Result: " << result);
-
-    result = smack_have_access(TEST_SUBJECT, TEST_OBJECT, "rwx");
-    if(result != -1) {
-        clean_up();
-        RUNNER_FAIL_MSG("smack_have_access should return error (SMACK is off). Result: "
-                        << result);
-    }
-
-    clean_up();
-}
-
-/**
- * NOSMACK version of smack09 test.
- *
- * This test checks if smack_new_label_from_socket reacts correctly. Since label should be
- * acquired from getsockopt, and it should fail, we must only set up socket and call
- * smack_new_label_from_socket. It should return error.
- */
-RUNNER_CHILD_TEST_NOSMACK(smack09_new_label_from_socket_nosmack)
-{
-    int pid;
-    struct sockaddr_un sockaddr = {AF_UNIX, SOCK_PATH};
-    unlink(SOCK_PATH);
-    char* smack_label;
-
-    pid = fork();
-    RUNNER_ASSERT_ERRNO_MSG(pid >= 0, "Fork failed");
-    if (!pid) { //child (server)
-        int sock, result;
-        int fd;
-
-        //Create new socket
-        sock = socket(AF_UNIX, SOCK_STREAM, 0);
-        RUNNER_ASSERT_ERRNO_MSG(sock >= 0, "socket failed");
-        SockUniquePtr sock_ptr(&sock);
-
-        //Bind it to sockaddr
-        result = bind(sock, (struct sockaddr*) &sockaddr, sizeof(struct sockaddr_un));
-        RUNNER_ASSERT_ERRNO_MSG(result == 0, "bind failed");
-
-        //Prepare for listening
-        result = listen(sock, 1);
-        RUNNER_ASSERT_ERRNO_MSG(result == 0, "listen failed");
-
-        //Accept client
-        alarm(2);
-        fd = accept(sock, nullptr, nullptr);
-        alarm(0);
-        RUNNER_ASSERT_ERRNO_MSG(fd >= 0, "Failed when accepting connection from client");
-        FdUniquePtr fd_ptr(&fd);
-
-        //wait for smack_new_label_from_socket execution
-        usleep(200);
-
-        //Close server
-        exit(0);
-    }
-    else { //parent (client)
-        //Wait a little bit until server is set up
-        sleep(1);
-        int sock, result;
-
-        //Create socket
-        sock = socket(AF_UNIX, SOCK_STREAM, 0);
-        RUNNER_ASSERT_ERRNO_MSG(sock >= 0, "socket failed");
-        SockUniquePtr sock_ptr(&sock);
-
-        //Connect to sockaddr
-        result = connect(sock, (struct sockaddr*) &sockaddr,
-                sizeof(struct sockaddr_un));
-        RUNNER_ASSERT_ERRNO_MSG(result == 0, "connect failed");
-
-        //Try getting label, should fail beacuse getsockopt won't get anything
-        result = smack_new_label_from_socket(sock, &smack_label);
-        RUNNER_ASSERT_MSG(result == -1, "smack_new_label_from_socket should fail.");
-    }
-}
diff --git a/src/libsmack-tests/test_smack_rules b/src/libsmack-tests/test_smack_rules
deleted file mode 100644 (file)
index 4effa82..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-writer book rw----
-reader book r-----
diff --git a/src/libsmack-tests/test_smack_rules2 b/src/libsmack-tests/test_smack_rules2
deleted file mode 100644 (file)
index 7708bb2..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-test_subject_01 test_object_01 ---
-test_subject_01 test_object_02 rwatl
-test_subject_01 test_object_03 wat
-test_subject_02 test_object_01 -------
-test_subject_02 test_object_02 wa-lt
-test_subject_02 test_object_03 -rw--r------
-test_subject_03 test_object_01 aaaaaa ------
-test_subject_03 test_object_02 rwat
-test_subject_03 test_object_03 w---l-
diff --git a/src/libsmack-tests/test_smack_rules3 b/src/libsmack-tests/test_smack_rules3
deleted file mode 100644 (file)
index e11b322..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-test_subject_01 test_object_01 rwatl
-test_subject_01 test_object_02
-test_subject_01 test_object_03 xxxxx
diff --git a/src/libsmack-tests/test_smack_rules4 b/src/libsmack-tests/test_smack_rules4
deleted file mode 100644 (file)
index 194ef01..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-test_subject_01 test_object_01 rwxatl
-test_subject_01 test_object_02 +rwh4r9d32!@#$ 49$%^x2 rwxat
-test_subject_01 test_object_03 aaaaaa xxxxxx
diff --git a/src/libsmack-tests/test_smack_rules_full b/src/libsmack-tests/test_smack_rules_full
deleted file mode 100644 (file)
index b8600a5..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-test_subject_01 test_object_01 rwxatl
-test_subject_01 test_object_02 rwxatl
-test_subject_01 test_object_03 rwxatl
-test_subject_02 test_object_01 rwxatl
-test_subject_02 test_object_02 rwxatl
-test_subject_02 test_object_03 rwxatl
-test_subject_03 test_object_01 rwxatl
-test_subject_03 test_object_02 rwxatl
-test_subject_03 test_object_03 rwxatl
index 6571f9c..3a5a9d3 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2016-2020 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.
@@ -20,7 +20,7 @@
 #include <sys/un.h>
 #include <unistd.h>
 
-#include <access_provider.h>
+#include <app_context.h>
 #include <cynara_helpers_creds.h>
 #include <dpl/test/test_runner.h>
 #include <label_generator.h>
@@ -60,8 +60,8 @@ private:
 
 void udsServer(SynchronizationPipe &pipe, const struct sockaddr_un &sockaddr,
                const struct ProcessCredentials &peerCredentials) {
-    SecurityServer::AccessProvider ap(peerCredentials.label());
-    ap.applyAndSwithToUser(peerCredentials.uid(), peerCredentials.gid());
+    AppContext ctx(peerCredentials.label());
+    ctx.apply(peerCredentials.uid(), peerCredentials.gid());
     pipe.claimChildEp();
 
     int sock = UDSHelpers::createServer(&sockaddr);
index 3584e95..3e5f249 100644 (file)
@@ -52,7 +52,6 @@ function printSummary
     printf "\n"
 }
 
-runTest smack
 runTest security-manager
 runTest cynara
 runTest ckm
index 1cf60b6..d6f5a93 100644 (file)
@@ -1,7 +1,7 @@
 #!/bin/sh
 
 #####################################################################
-# Copyright (c) 2012 - 2019 Samsung Electronics Co., Ltd All Rights Reserved
+# Copyright (c) 2012 - 2020 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.
@@ -22,12 +22,6 @@ echo "### Starting tests ######################################################"
 
 case $1 in
 
-"smack")
-    echo "========================================================================="
-    echo $1
-    echo
-    libsmack-test "${@:2}" # propagate all remaining arguments (except first)
-    ;;
 "security-manager")
     echo "========================================================================="
     echo "SECURITY MANAGER TESTS"
@@ -66,7 +60,7 @@ case $1 in
     echo "Correct using:"
     echo "    security_test.sh <module> <args_for_module>"
     echo
-    echo "modules: smack, security-manager, cynara, ckm, yaca, nether"
+    echo "modules: security-manager, cynara, ckm, yaca, nether"
     ;;
 
 esac