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";
24 static int checkInternetPrivilegeCb(const char *privilegeName, void *user_data)
26 bool* ret = (bool*)user_data;
27 if (!strcmp(privilegeName, INTERNET_PRIVILEGE)) {
34 void checkInternetPrivilegeAndDisableIPv6(const char* pkgId, const std::string& rootPath)
36 bool isInternetPrivilegeExisted = false;
37 pkgmgrinfo_pkginfo_h pkg_handle;
38 int ret = pkgmgrGetPkgInfo(pkgId, &pkg_handle);
43 ret = pkgmgrinfo_pkginfo_foreach_privilege(pkg_handle, checkInternetPrivilegeCb, &isInternetPrivilegeExisted);
44 if (ret != PMINFO_R_OK) {
45 _SERR("Failed to pkgmgrinfo_pkginfo_foreach_privilege");
46 pkgmgrinfo_pkginfo_destroy_pkginfo(pkg_handle);
50 if (!isInternetPrivilegeExisted) {
51 std::string ipv6FilePath = rootPath + "/bin/" + DISABLE_IPV6_FILE;
52 std::ofstream output(ipv6FilePath);
53 if (exist(ipv6FilePath)) {
54 copySmackAndOwnership(rootPath + "/bin/", ipv6FilePath);
55 _INFO("File to disable IPv6 is created successfully");
57 _SERR("Failed to create file to disable IPv6 [%s]", pkgId);
62 pkgmgrinfo_pkginfo_destroy_pkginfo(pkg_handle);
65 static int checkAppPrivilegeListCb(pkgmgrinfo_appinfo_h handle, void *user_data)
70 ret = pkgmgrinfo_appinfo_get_apptype(handle, &appType);
71 if (ret != PMINFO_R_OK) {
72 _SERR("Failed to get apptype");
76 // skip if appType is NULL or appType does not contains "dotnet",
77 if (appType == NULL || (appType != NULL && strstr(appType, "dotnet") == NULL)) {
82 ret = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgId);
83 if (ret != PMINFO_R_OK || pkgId == NULL) {
84 _SERR("Failed to get package id");
88 char *rootPath = NULL;
89 ret = pkgmgrinfo_appinfo_get_root_path(handle, &rootPath);
90 if (ret != PMINFO_R_OK) {
91 _SERR("Failed to get root path");
95 checkInternetPrivilegeAndDisableIPv6(pkgId, rootPath);
100 void checkAllAppPrivilege()
102 int ret = pkgmgrinfo_appinfo_get_installed_list(checkAppPrivilegeListCb, NULL);
103 if (ret != PMINFO_R_OK) {
104 _SERR("Failed to get installed list");