Changed API to check internet privilege
authorj-h.choi <j-h.choi@samsung.com>
Thu, 13 Oct 2022 07:56:08 +0000 (16:56 +0900)
committer조웅석/Common Platform Lab(SR)/삼성전자 <ws77.cho@samsung.com>
Fri, 14 Oct 2022 02:15:57 +0000 (11:15 +0900)
Change-Id: I9952150b11e561e1d89b5d8ce4798fdcddb62e0d

NativeLauncher/CMakeLists.txt
NativeLauncher/tool/privilege_common.cc
packaging/dotnet-launcher.spec

index 28ee598..302008a 100644 (file)
@@ -4,7 +4,7 @@ PROJECT("dotnet-tools")
 MESSAGE("CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}")
 
 INCLUDE(FindPkgConfig)
-PKG_CHECK_MODULES(${PROJECT_NAME} REQUIRED aul pkgmgr-info pkgmgr-installer ecore bundle dlog liblaunchpad glib-2.0 libsmack capi-appfw-app-common storage jsoncpp openssl1.1 sqlite3 libtzplatform-config security-manager)
+PKG_CHECK_MODULES(${PROJECT_NAME} REQUIRED aul pkgmgr-info pkgmgr-installer ecore bundle dlog liblaunchpad glib-2.0 libsmack capi-appfw-app-common storage jsoncpp openssl1.1 sqlite3 libtzplatform-config)
 
 FOREACH(flag ${${PROJECT_NAME}_CFLAGS})
     SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
index 8b7ba2d..5c5f991 100644 (file)
 #include "privilege_common.h"
 #include "launcher_env.h"
 
-#include <app-runtime.h>
-
 static const char* INTERNET_PRIVILEGE = "http://tizen.org/privilege/internet";
-static int UID_OWNER = 5001;
+bool isInternetPrivilegeExisted = false;
+
+static int checkInternetPrivilegeCb(const char *privilegeName, void *user_data)
+{
+       if (!strcmp(privilegeName, INTERNET_PRIVILEGE)) {
+               isInternetPrivilegeExisted = true;
+               return -1;
+       }
+       return 0;
+}
 
 void checkInternetPrivilegeAndDisableIPv6(const char* pkgId, const std::string& rootPath)
 {
-       int res = 0;
-       if (security_manager_app_has_privilege(pkgId, INTERNET_PRIVILEGE, UID_OWNER, &res) == SECURITY_MANAGER_SUCCESS) {
-               if (res != 1) {
-                       std::string filePath = rootPath + "/bin/" + DISABLE_IPV6_FILE;
-                       std::ofstream output(filePath);
-                       if (exist(filePath)) {
-                               _INFO("File to disable IPv6 is created successfully");
-                       } else {
-                               _ERR("Failed to create file to disable IPv6 [%s]", pkgId);
-                       }
-                       output.close();
+       pkgmgrinfo_pkginfo_h pkg_handle;
+       int ret = pkgmgrGetPkgInfo(pkgId, &pkg_handle);
+       if (ret != 0) {
+               return;
+       }
+
+       ret = pkgmgrinfo_pkginfo_foreach_privilege(pkg_handle, checkInternetPrivilegeCb, NULL);
+       if (ret != PMINFO_R_OK) {
+               _SERR("Failed to pkgmgrinfo_pkginfo_foreach_privilege");
+               pkgmgrinfo_pkginfo_destroy_pkginfo(pkg_handle);
+               return;
+       }
+
+       if (!isInternetPrivilegeExisted) {
+               std::string filePath = rootPath + "/bin/" + DISABLE_IPV6_FILE;
+               std::ofstream output(filePath);
+               if (exist(filePath)) {
+                       _INFO("File to disable IPv6 is created successfully");
+               } else {
+                       _SERR("Failed to create file to disable IPv6 [%s]", pkgId);
                }
+               output.close();
        }
+
+       pkgmgrinfo_pkginfo_destroy_pkginfo(pkg_handle);
 }
 
 static int checkAppPrivilegeListCb(pkgmgrinfo_appinfo_h handle, void *user_data)
@@ -81,7 +100,7 @@ static void checkAppPrivilegeByAppType(const char* type)
 
        ret = pkgmgrinfo_appinfo_filter_foreach_appinfo(filter, checkAppPrivilegeListCb, NULL);
        if (ret != PMINFO_R_OK) {
-               _SERR("Failed to pkgmgrinfo_pkginfo_filter_foreach_pkginfo");
+               _SERR("Failed to pkgmgrinfo_appinfo_filter_foreach_appinfo");
                pkgmgrinfo_appinfo_filter_destroy(filter);
                return;
        }
index 88c3e93..e44f13a 100644 (file)
@@ -25,7 +25,6 @@ BuildRequires: pkgconfig(jsoncpp)
 BuildRequires: pkgconfig(openssl1.1)
 BuildRequires: pkgconfig(libsystemd)
 BuildRequires: pkgconfig(libtzplatform-config)
-BuildRequires: pkgconfig(security-manager)
 BuildRequires: sqlite-devel
 BuildRequires: boost-devel
 BuildRequires: aul-devel