Add switch to disable IPv6
[platform/core/dotnet/launcher.git] / NativeLauncher / installer-plugin / dotnet_apptype_plugin.cc
1 /*
2  * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 #include "log.h"
18 #include "utils.h"
19 #include "multi_target_resolver.h"
20 #include "ni_common.h"
21 #include "launcher_env.h"
22
23 #include <vector>
24 #include <app-runtime.h>
25
26 #ifdef  LOG_TAG
27 #undef  LOG_TAG
28 #endif
29 #define LOG_TAG "DOTNET_INSTALLER_PLUGIN"
30
31 typedef struct _xmlDoc xmlDoc;
32 typedef xmlDoc* xmlDocPtr;
33
34 bool pluginInstalled = false;
35 static const char* INTERNET_PRIVILEGE = "http://tizen.org/privilege/internet";
36 static int UID_OWNER = 5001;
37
38 static void checkPrivilegeAndDisableIPv6(const char* pkgId, const std::string& rootPath)
39 {
40         int res = 0;
41         if (security_manager_app_has_privilege(pkgId, INTERNET_PRIVILEGE, UID_OWNER, &res) == SECURITY_MANAGER_SUCCESS) {
42                 if (res != 1) {
43                         std::string filePath = rootPath + "/bin/" + DISABLE_IPV6_FILE;
44                         std::ofstream output(filePath);
45                         if (exist(filePath)) {
46                                 _INFO("File to disable IPv6 is created successfully");
47                         } else {
48                                 _ERR("Failed to create file to disable IPv6 [%s]", pkgId);
49                         }
50                 }
51         }
52 }
53
54 extern "C" int PKGMGR_PARSER_PLUGIN_INSTALL(xmlDocPtr doc, const char* pkgId)
55 {
56         // Can be multiple apps in one package
57         if (pluginInstalled) {
58                 _INFO("Plugin already installed");
59                 return 0;
60         }
61         pluginInstalled = true;
62
63         std::string appType = getAppType(pkgId);
64         if (appType.empty()) {
65                 _ERR("Failed to get app type from [%s]", pkgId);
66                 return 0;
67         }
68
69         if (appType.find("dotnet") == std::string::npos) {
70                 return 0;
71         }
72
73         std::string rootPath = getRootPath(pkgId);
74         if (rootPath.empty()) {
75                 _ERR("Failed to get root path from [%s]", pkgId);
76                 return 0;
77         }
78
79         if (removeAppProfileData(pkgId) != NI_ERROR_NONE) {
80                 _ERR("Failed to remove [%s] profile data", pkgId);
81         }
82
83         if (resolvePlatformSpecificFiles(rootPath) != 0) {
84                 _ERR("Failed to resolve platform specific resources of nuget");
85         }
86
87         checkPrivilegeAndDisableIPv6(pkgId, rootPath);
88
89         return 0;
90 }
91 extern "C" int PKGMGR_PARSER_PLUGIN_UPGRADE(xmlDocPtr doc, const char* pkgId)
92 {
93         return PKGMGR_PARSER_PLUGIN_INSTALL(doc, pkgId);
94 }
95 extern "C" int PKGMGR_PARSER_PLUGIN_UNINSTALL(xmlDocPtr doc, const char* pkgId)
96 {
97         return 0;
98 }
99 extern "C" int PKGMGR_PARSER_PLUGIN_REMOVED(xmlDocPtr doc, const char* pkgId)
100 {
101         return 0;
102 }
103 extern "C" int PKGMGR_PARSER_PLUGIN_CLEAN(xmlDocPtr doc, const char* pkgId)
104 {
105         return 0;
106 }
107 extern "C" int PKGMGR_PARSER_PLUGIN_UNDO(xmlDocPtr doc, const char* pkgId)
108 {
109         return 0;
110 }
111 extern "C" int PKGMGR_PARSER_PLUGIN_PRE_INSTALL(const char *pkgId)
112 {
113         return 0;
114 }
115 extern "C" int PKGMGR_PARSER_PLUGIN_PRE_UPGRADE(const char *pkgId)
116 {
117         return 0;
118 }
119 extern "C" int PKGMGR_PARSER_PLUGIN_PRE_UNINSTALL(const char *pkgId)
120 {
121         return 0;
122 }
123 extern "C" int PKGMGR_PARSER_PLUGIN_POST_INSTALL(const char *pkgId)
124 {
125         return 0;
126 }
127 extern "C" int PKGMGR_PARSER_PLUGIN_POST_UPGRADE(const char *pkgId)
128 {
129         return 0;
130 }
131 extern "C" int PKGMGR_PARSER_PLUGIN_POST_UNINSTALL(const char *pkgId)
132 {
133         return 0;
134 }