Add support for Application Defined Privileges 40/113740/4
authorBartlomiej Grzelewski <b.grzelewski@samsung.com>
Fri, 3 Feb 2017 15:48:45 +0000 (16:48 +0100)
committerBartlomiej Grzelewski <b.grzelewski@samsung.com>
Mon, 20 Feb 2017 17:51:32 +0000 (18:51 +0100)
Change-Id: I51122a50ac1b6f0c169659c07fcc9da02bd3ef36

src/security-manager-tests/common/app_install_helper.cpp
src/security-manager-tests/common/app_install_helper.h
src/security-manager-tests/common/scoped_installer.h
src/security-manager-tests/common/sm_request.cpp
src/security-manager-tests/common/sm_request.h

index 0436241..cd352f6 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014-2016 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2014-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.
@@ -153,6 +153,14 @@ std::vector<std::string> AppInstallHelper::getPrivileges() const {
     return m_privileges;
 }
 
+void AppInstallHelper::addAppDefinedPrivilege(const std::string &privilege) {
+    m_appDefinedPrivileges.push_back(privilege);
+}
+
+std::vector<std::string> AppInstallHelper::getAppDefinedPrivileges() const {
+    return m_appDefinedPrivileges;
+}
+
 void AppInstallHelper::revokeRules() const {
     RUNNER_ASSERT_MSG(
         0 == smack_revoke_subject(generateAppLabel().c_str()),
index 883dd0e..c4d083e 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014-2016 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2014-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.
@@ -110,6 +110,9 @@ struct AppInstallHelper {
     void addPrivileges(const std::vector<std::string> &privileges);
     std::vector<std::string> getPrivileges() const;
 
+    void addAppDefinedPrivilege(const std::string &privilege);
+    std::vector<std::string> getAppDefinedPrivileges() const;
+
     // Smack
     std::string generateAppLabel() const;
     std::string generatePkgLabel() const;
@@ -134,6 +137,7 @@ protected:
     TypePathsMap m_dirTypeMap;
     TypePathsMap m_fileTypeMap;
     std::vector<std::string> m_privileges;
+    std::vector<std::string> m_appDefinedPrivileges;
     std::string m_author;
 
     pid_t m_creatorPid;
index 639aa11..6ec37c2 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.
@@ -60,9 +60,11 @@ public:
         for (const auto& typePaths : app.getFilesMap())
             for (const auto& path : typePaths.second)
                 instReq.addPath(path, typePaths.first);
-        for (const auto &priv : app.getPrivileges()) {
+        for (const auto &priv : app.getPrivileges())
             instReq.addPrivilege(priv.c_str());
-        }
+        for (const auto &priv : app.getAppDefinedPrivileges())
+            instReq.addAppDefinedPrivilege(priv);
+
         SecurityManagerTest::Api::install(instReq);
     }
 
index 2bba17c..5f5f5a2 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014-2016 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2014-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.
@@ -95,6 +95,17 @@ void InstallRequest::addPrivilege(const std::string &privilege, lib_retcode expe
     m_privileges.push_back(privilege);
 }
 
+void InstallRequest::addAppDefinedPrivilege(const std::string &privilege, lib_retcode expectedResult)
+{
+    int result = security_manager_app_inst_req_add_app_defined_privilege(m_req, privilege.c_str());
+    RUNNER_ASSERT_MSG((lib_retcode)result == expectedResult,
+                      "adding app defined privilege returned wrong value."
+                          << " Privilege: " << privilege << ";"
+                          << " Result: " << result << ";"
+                          << " Expected result: " << expectedResult);
+    m_appDefinedPrivileges.push_back(privilege);
+}
+
 void InstallRequest::addPath(std::string path, app_install_path_type pathType, lib_retcode expectedResult)
 {
     int result = security_manager_app_inst_req_add_path(m_req, path.c_str(), pathType);
@@ -162,6 +173,13 @@ std::ostream& operator<<(std::ostream &os, const InstallRequest &request)
         }
         os << " ]";
     }
+    if (!request.m_appDefinedPrivileges.empty()) {
+        os << "app defined privileges: [ " << request.m_appDefinedPrivileges[0];
+        for (size_t i = 1; i < request.m_appDefinedPrivileges.size(); ++i)
+            os << "; " << request.m_appDefinedPrivileges[i];
+        os << " ]";
+    }
+
     if (!request.m_paths.empty()) {
         os << "paths: [ " << "< " << request.m_paths[0].first << "; "
                                   << request.m_paths[0].second << " >";
index ee72521..abdbb42 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014-2016 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2014-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.
@@ -59,6 +59,7 @@ public:
     void setAppId(std::string appId, lib_retcode expectedresult = SECURITY_MANAGER_SUCCESS);
     void setPkgId(std::string pkgId, lib_retcode expectedresult = SECURITY_MANAGER_SUCCESS);
     void addPrivilege(const std::string &privilege, lib_retcode expectedresult = SECURITY_MANAGER_SUCCESS);
+    void addAppDefinedPrivilege(const std::string &privilege, lib_retcode expectedResult = SECURITY_MANAGER_SUCCESS);
     void addPath(std::string path, app_install_path_type pathType,
                  lib_retcode expectedResult = SECURITY_MANAGER_SUCCESS);
     void setUid(const uid_t uid, lib_retcode expectedresult = SECURITY_MANAGER_SUCCESS);
@@ -78,6 +79,7 @@ private:
     std::string m_pkgId;
     std::string m_authorId;
     std::vector<std::string> m_privileges;
+    std::vector<std::string> m_appDefinedPrivileges;
     std::vector<std::pair<std::string, app_install_path_type> > m_paths;
     std::pair<bool, uid_t> m_uid;
 };