Move label generation to global commons 45/148745/2
authorZofia Abramowska <z.abramowska@samsung.com>
Thu, 7 Sep 2017 14:47:20 +0000 (16:47 +0200)
committerZofia Abramowska <z.abramowska@samsung.com>
Fri, 15 Sep 2017 18:42:16 +0000 (20:42 +0200)
Change-Id: Ic38d65e29394dc5b8e784a8af6b105460e52a259

src/common/CMakeLists.txt
src/common/label_generator.cpp [new file with mode: 0644]
src/common/label_generator.h [new file with mode: 0644]
src/security-manager-tests/common/app_install_helper.cpp
src/security-manager-tests/common/sm_commons.cpp
src/security-manager-tests/common/sm_commons.h
src/security-manager-tests/test_cases.cpp
src/security-manager-tests/test_cases_credentials.cpp
src/security-manager-tests/test_cases_dyntransition.cpp
src/security-manager-tests/test_cases_register_paths.cpp

index 4fd8953..cfb01ee 100644 (file)
@@ -33,6 +33,7 @@ SET(COMMON_TARGET_TEST_SOURCES
     ${PROJECT_SOURCE_DIR}/src/common/timeout.cpp
     ${PROJECT_SOURCE_DIR}/src/common/temp_test_user.cpp
     ${PROJECT_SOURCE_DIR}/src/common/cynara_helpers_creds.cpp
+    ${PROJECT_SOURCE_DIR}/src/common/label_generator.cpp
     )
 
 #system and local includes
diff --git a/src/common/label_generator.cpp b/src/common/label_generator.cpp
new file mode 100644 (file)
index 0000000..6fc5140
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2017 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.
+ */
+
+#include <label_generator.h>
+
+// Common implementation details
+std::string generateProcessLabel(const std::string &appId, const std::string &pkgId, bool isHybrid)
+{
+    std::string label = "User::Pkg::" + pkgId;
+    if (isHybrid) {
+        label += "::App::" + appId;
+    }
+    return label;
+}
+
+std::string generatePathRWLabel(const std::string &pkgId)
+{
+    return "User::Pkg::" + pkgId;
+}
+
+std::string generatePathROLabel(const std::string &pkgId)
+{
+    return generatePathRWLabel(pkgId) + "::RO";
+}
+
+std::string generatePathSharedROLabel(const std::string &pkgId)
+{
+    return generatePathRWLabel(pkgId) + "::SharedRO";
+}
+
+std::string generatePathTrustedLabel(int64_t authorId)
+{
+    return "User::Author::" + std::to_string(authorId);
+}
+
+std::string getPublicPathLabel()
+{
+    return "User::Home";
+}
diff --git a/src/common/label_generator.h b/src/common/label_generator.h
new file mode 100644 (file)
index 0000000..8c99ed4
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2017 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.
+ */
+
+#include <string>
+#include <sys/types.h>
+
+std::string generateProcessLabel(const std::string &appId, const std::string &pkgId, bool isHybrid = false);
+std::string generatePathRWLabel(const std::string &pkgId);
+std::string generatePathROLabel(const std::string &pkgId);
+std::string generatePathSharedROLabel(const std::string &pkgId);
+std::string generatePathTrustedLabel(int64_t authorId);
+std::string getPublicPathLabel();
index f1865fe..b9f3073 100644 (file)
@@ -26,8 +26,8 @@
 #include <security-manager-types.h>
 
 #include <dpl/test/test_runner.h>
-#include <sm_commons.h>
 #include <tzplatform.h>
+#include <label_generator.h>
 
 #include "app_install_helper.h"
 
index bd583a2..d6b0ee8 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2016-2017 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.
 #include <tests_common.h>
 #include <policy_configuration.h>
 #include "tzplatform.h"
+#include <label_generator.h>
 
 using namespace SecurityManagerTest;
 
-// Common implementation details
-
-std::string generateProcessLabel(const std::string &appId, const std::string &pkgId, bool isHybrid)
-{
-    std::string label = "User::Pkg::" + pkgId;
-    if (isHybrid) {
-        label += "::App::" + appId;
-    }
-    return label;
-}
-
-std::string generatePathRWLabel(const std::string &pkgId)
-{
-    return "User::Pkg::" + pkgId;
-}
-
-std::string generatePathROLabel(const std::string &pkgId)
-{
-    return generatePathRWLabel(pkgId) + "::RO";
-}
-
-std::string generatePathSharedROLabel(const std::string &pkgId)
-{
-    return generatePathRWLabel(pkgId) + "::SharedRO";
-}
-
-std::string generatePathTrustedLabel(int64_t authorId)
-{
-    return "User::Author::" + std::to_string(authorId);
-}
-
-std::string getPublicPathLabel()
-{
-    return "User::Home";
-}
-
 // Common DB/nftw checks
 
 // nftw doesn't allow passing user data to functions. Work around by using global variable
index 346c1f7..02e9a13 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2016-2017 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.
@@ -35,13 +35,6 @@ DEFINE_SMARTPTR(cap_free, _cap_struct, CapsSetsUniquePtr);
 
 const int FTW_MAX_FDS = 16;
 
-std::string generateProcessLabel(const std::string &appId, const std::string &pkgId, bool isHybrid = false);
-std::string generatePathRWLabel(const std::string &pkgId);
-std::string generatePathROLabel(const std::string &pkgId);
-std::string generatePathSharedROLabel(const std::string &pkgId);
-std::string generatePathTrustedLabel(int64_t authorId);
-std::string getPublicPathLabel();
-
 typedef std::vector<std::string> privileges_t;
 
 int nftw_remove_labels(const char *fpath, const struct stat* /*sb*/,
index 3d80230..406d303 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2016-2017 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.
@@ -31,6 +31,7 @@
 #include <app_install_helper.h>
 #include <cynara_test_admin.h>
 #include <dpl/test/test_runner.h>
+#include <label_generator.h>
 #include <message_pipe.h>
 #include <policy_configuration.h>
 #include <scoped_installer.h>
index 90d74a9..6571f9c 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2016-2017 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.
@@ -23,6 +23,7 @@
 #include <access_provider.h>
 #include <cynara_helpers_creds.h>
 #include <dpl/test/test_runner.h>
+#include <label_generator.h>
 #include <memory.h>
 #include <passwd_access.h>
 #include <sm_api.h>
index e2b2ba6..3c8c607 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2016-2017 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.
@@ -23,6 +23,7 @@
 
 #include <app_install_helper.h>
 #include <dpl/test/test_runner.h>
+#include <label_generator.h>
 #include <memory.h>
 #include <message_pipe.h>
 #include <scoped_installer.h>
@@ -43,6 +44,7 @@ struct UidGidMsg {
 static void testSetLabelForSelf(const std::string &appName, const std::string &pkgName,
                                 bool expected_success)
 {
+    //FIXME : replace this with SM API
     std::string label =  generateProcessLabel(appName, pkgName);
     int result = smack_set_label_for_self(label.c_str());
     if (expected_success)
index 9a12555..88e0896 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2016-2017 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.
@@ -18,6 +18,7 @@
 
 #include <app_install_helper.h>
 #include <dpl/test/test_runner.h>
+#include <label_generator.h>
 #include <scoped_installer.h>
 #include <sm_api.h>
 #include <sm_commons.h>