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 #include <app-runtime.h>
24 static const char* INTERNET_PRIVILEGE = "http://tizen.org/privilege/internet";
25 static int UID_OWNER = 5001;
27 void checkInternetPrivilegeAndDisableIPv6(const char* pkgId, const std::string& rootPath)
30 if (security_manager_app_has_privilege(pkgId, INTERNET_PRIVILEGE, UID_OWNER, &res) == SECURITY_MANAGER_SUCCESS) {
32 std::string filePath = rootPath + "/bin/" + DISABLE_IPV6_FILE;
33 std::ofstream output(filePath);
34 if (exist(filePath)) {
35 _INFO("File to disable IPv6 is created successfully");
37 _ERR("Failed to create file to disable IPv6 [%s]", pkgId);
44 static int checkAppPrivilegeListCb(pkgmgrinfo_appinfo_h handle, void *user_data)
47 int ret = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgId);
48 if (ret != PMINFO_R_OK || pkgId == NULL) {
49 _SERR("Failed to get package id");
53 char *rootPath = NULL;
54 ret = pkgmgrinfo_appinfo_get_root_path(handle, &rootPath);
55 if (ret != PMINFO_R_OK) {
56 _SERR("Failed to get root path");
60 checkInternetPrivilegeAndDisableIPv6(pkgId, rootPath);
65 static void checkAppPrivilegeByAppType(const char* type)
67 pkgmgrinfo_appinfo_filter_h filter;
69 int ret = pkgmgrinfo_appinfo_filter_create(&filter);
70 if (ret != PMINFO_R_OK) {
71 _SERR("Failed to create appinfo filter");
75 ret = pkgmgrinfo_appinfo_filter_add_string(filter, PMINFO_APPINFO_PROP_APP_TYPE, type);
76 if (ret != PMINFO_R_OK) {
77 pkgmgrinfo_appinfo_filter_destroy(filter);
78 _SERR("Failed to add appinfo filter (%s)", type);
82 ret = pkgmgrinfo_appinfo_filter_foreach_appinfo(filter, checkAppPrivilegeListCb, NULL);
83 if (ret != PMINFO_R_OK) {
84 _SERR("Failed to pkgmgrinfo_pkginfo_filter_foreach_pkginfo");
85 pkgmgrinfo_appinfo_filter_destroy(filter);
89 pkgmgrinfo_appinfo_filter_destroy(filter);
94 void checkAllAppPrivilege()
96 std::vector<const char*> appTypeList = {"dotnet", "dotnet-nui", "dotnet-inhouse"};
98 for (auto& type : appTypeList) {
99 checkAppPrivilegeByAppType(type);