Remove ugly manual setup of pkgmgr database 27/232927/2
authorTomasz Swierczek <t.swierczek@samsung.com>
Fri, 8 May 2020 09:35:07 +0000 (11:35 +0200)
committerDariusz Michaluk <d.michaluk@samsung.com>
Thu, 14 May 2020 09:43:44 +0000 (09:43 +0000)
Use new SM APIs instead so privilege-checker
doesn't have to call pkgmgr.

Change-Id: I15cdee3693ec1f16c789a9234e12703c2a6b3fcf

src/common/sm_api.cpp
src/common/sm_request.cpp

index bc70ea0..dd1af2c 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014-2019 Samsung Electronics Co., Ltd. All rights reserved
+ * Copyright (c) 2014-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.
@@ -27,35 +27,13 @@ namespace Api {
 
 void install(const InstallRequest &request, lib_retcode expectedResult)
 {
-    uid_t uid = getuid();
-    std::string dbPath = uid == 0 ? "/opt/dbspace/" : "/opt/dbspace/user/" + std::to_string(uid) + "/";
-
-    std::ostringstream command;
-    command << "/usr/bin/sqlite3 "
-            << dbPath << ".pkgmgr_parser.db "
-            << " \"insert into package_info (package, package_type, package_api_version,"
-            << " install_location, mainapp_id, root_path, installed_storage)"
-            << " values ('" << request.getPkgId() << "', 'tpk', '" << request.getAppTizenVersion()
-            << "', 'auto', '" << request.getPkgId() << "', '/opt/usr/globallapps/"
-            << request.getPkgId() << "', 'installed_internal')\"";
-    int pkgmgrResult = system(command.str().c_str());
-    RUNNER_ASSERT_MSG(pkgmgrResult == 0, "failed to set package_info: " << pkgmgrResult);
-
     int result = security_manager_app_install(request.get());
 
-    command = std::ostringstream();
-    command << "/usr/bin/sqlite3 "
-            << dbPath << ".pkgmgr_parser.db "
-            << " \"delete from package_info where package='" << request.getPkgId() << "'\"";
-    pkgmgrResult = system(command.str().c_str());
-
     RUNNER_ASSERT_MSG((lib_retcode)result == expectedResult,
                       "installing app returned wrong value."
                       << " InstallRequest: [ " << request << "];"
                       << " Result: " << result << ";"
                       << " Expected result: " << expectedResult);
-
-    RUNNER_ASSERT_MSG(pkgmgrResult == 0, "failed to unset package_info: " << pkgmgrResult);
 }
 
 void update(const InstallRequest &request, lib_retcode expectedResult)
index b6fa1a1..89ec04d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014-2019 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2014-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.
@@ -44,6 +44,14 @@ InstallRequest::InstallRequest()
     RUNNER_ASSERT_MSG((lib_retcode)result == SECURITY_MANAGER_SUCCESS,
                       "creation of new request failed. Result: " << result);
     RUNNER_ASSERT_MSG(m_req != nullptr, "creation of new request did not allocate memory");
+    // platform level has the widest possible privilege spectrum available, hence using it for all apps
+    result = security_manager_app_inst_req_set_pkg_privilege_level(m_req, SM_PKG_PRIVILEGE_LEVEL_PLATFORM);
+    RUNNER_ASSERT_MSG((lib_retcode)result == SECURITY_MANAGER_SUCCESS,
+                      "setting privilege level failed. Result: " << result);
+    // core seems to map to TPK, which is what we're mimicking
+    result = security_manager_app_inst_req_set_pkg_type(m_req, SM_PKG_TYPE_CORE);
+    RUNNER_ASSERT_MSG((lib_retcode)result == SECURITY_MANAGER_SUCCESS,
+                      "setting package type. Result: " << result);
 }
 
 InstallRequest::~InstallRequest()