+/*
+ * Copyright (c) 2022 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "log.h"
+#include "utils.h"
+#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;
+
+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();
+ }
+ }
+}
+
+static int checkAppPrivilegeListCb(pkgmgrinfo_appinfo_h handle, void *user_data)
+{
+ char *pkgId = NULL;
+ int ret = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgId);
+ if (ret != PMINFO_R_OK || pkgId == NULL) {
+ _SERR("Failed to get package id");
+ return 0;
+ }
+
+ char *rootPath = NULL;
+ ret = pkgmgrinfo_appinfo_get_root_path(handle, &rootPath);
+ if (ret != PMINFO_R_OK) {
+ _SERR("Failed to get root path");
+ return 0;
+ }
+
+ checkInternetPrivilegeAndDisableIPv6(pkgId, rootPath);
+
+ return 0;
+}
+
+static void checkAppPrivilegeByAppType(const char* type)
+{
+ pkgmgrinfo_appinfo_filter_h filter;
+
+ int ret = pkgmgrinfo_appinfo_filter_create(&filter);
+ if (ret != PMINFO_R_OK) {
+ _SERR("Failed to create appinfo filter");
+ return;
+ }
+
+ ret = pkgmgrinfo_appinfo_filter_add_string(filter, PMINFO_APPINFO_PROP_APP_TYPE, type);
+ if (ret != PMINFO_R_OK) {
+ pkgmgrinfo_appinfo_filter_destroy(filter);
+ _SERR("Failed to add appinfo filter (%s)", type);
+ return;
+ }
+
+ ret = pkgmgrinfo_appinfo_filter_foreach_appinfo(filter, checkAppPrivilegeListCb, NULL);
+ if (ret != PMINFO_R_OK) {
+ _SERR("Failed to pkgmgrinfo_pkginfo_filter_foreach_pkginfo");
+ pkgmgrinfo_appinfo_filter_destroy(filter);
+ return;
+ }
+
+ pkgmgrinfo_appinfo_filter_destroy(filter);
+
+ return;
+}
+
+void checkAllAppPrivilege()
+{
+ std::vector<const char*> appTypeList = {"dotnet", "dotnet-nui", "dotnet-inhouse"};
+
+ for (auto& type : appTypeList) {
+ checkAppPrivilegeByAppType(type);
+ }
+}