2 * Copyright (c) 2022 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include "privilege_common.h"
20 #include "launcher_env.h"
22 static const char* INTERNET_PRIVILEGE = "http://tizen.org/privilege/internet";
23 bool isInternetPrivilegeExisted = false;
25 static int checkInternetPrivilegeCb(const char *privilegeName, void *user_data)
27 if (!strcmp(privilegeName, INTERNET_PRIVILEGE)) {
28 isInternetPrivilegeExisted = true;
34 void checkInternetPrivilegeAndDisableIPv6(const char* pkgId, const std::string& rootPath)
36 pkgmgrinfo_pkginfo_h pkg_handle;
37 int ret = pkgmgrGetPkgInfo(pkgId, &pkg_handle);
42 ret = pkgmgrinfo_pkginfo_foreach_privilege(pkg_handle, checkInternetPrivilegeCb, NULL);
43 if (ret != PMINFO_R_OK) {
44 _SERR("Failed to pkgmgrinfo_pkginfo_foreach_privilege");
45 pkgmgrinfo_pkginfo_destroy_pkginfo(pkg_handle);
49 if (!isInternetPrivilegeExisted) {
50 std::string filePath = rootPath + "/bin/" + DISABLE_IPV6_FILE;
51 std::ofstream output(filePath);
52 if (exist(filePath)) {
53 _INFO("File to disable IPv6 is created successfully");
55 _SERR("Failed to create file to disable IPv6 [%s]", pkgId);
60 pkgmgrinfo_pkginfo_destroy_pkginfo(pkg_handle);
63 static int checkAppPrivilegeListCb(pkgmgrinfo_appinfo_h handle, void *user_data)
66 int ret = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgId);
67 if (ret != PMINFO_R_OK || pkgId == NULL) {
68 _SERR("Failed to get package id");
72 char *rootPath = NULL;
73 ret = pkgmgrinfo_appinfo_get_root_path(handle, &rootPath);
74 if (ret != PMINFO_R_OK) {
75 _SERR("Failed to get root path");
79 checkInternetPrivilegeAndDisableIPv6(pkgId, rootPath);
84 static void checkAppPrivilegeByAppType(const char* type)
86 pkgmgrinfo_appinfo_filter_h filter;
88 int ret = pkgmgrinfo_appinfo_filter_create(&filter);
89 if (ret != PMINFO_R_OK) {
90 _SERR("Failed to create appinfo filter");
94 ret = pkgmgrinfo_appinfo_filter_add_string(filter, PMINFO_APPINFO_PROP_APP_TYPE, type);
95 if (ret != PMINFO_R_OK) {
96 pkgmgrinfo_appinfo_filter_destroy(filter);
97 _SERR("Failed to add appinfo filter (%s)", type);
101 ret = pkgmgrinfo_appinfo_filter_foreach_appinfo(filter, checkAppPrivilegeListCb, NULL);
102 if (ret != PMINFO_R_OK) {
103 _SERR("Failed to pkgmgrinfo_appinfo_filter_foreach_appinfo");
104 pkgmgrinfo_appinfo_filter_destroy(filter);
108 pkgmgrinfo_appinfo_filter_destroy(filter);
113 void checkAllAppPrivilege()
115 std::vector<const char*> appTypeList = {"dotnet", "dotnet-nui", "dotnet-inhouse"};
117 for (auto& type : appTypeList) {
118 checkAppPrivilegeByAppType(type);