Tizen 2.4.0 rev3 SDK Public Release
[framework/base/rpm-installer.git] / inc / installer-type.h
1 /*
2 *
3 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16  *
17  */
18
19 #ifndef _INSTALLER_TYPE_H_
20 #define _INSTALLER_TYPE_H_
21
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25
26 #include <dlog.h>
27 #include <glib.h>
28 #include <sys/stat.h>
29 #include <pkgmgr-info.h>
30
31 #ifdef  LOG_TAG
32 #undef  LOG_TAG
33 #define LOG_TAG         "rpm-installer"
34 #endif
35
36 #define INSTALLER_VERSION                                       "20150703.1"
37
38 #define BUF_SIZE                                                                        4096
39 #define SIZE_KB                                                                         1024
40 #define APP_OWNER_ID                                                    5000
41 #define APP_GROUP_ID                                                    5000
42 #define TERMINATE_RETRY_COUNT                   100
43 #define MAX_CERT_NUM                                                    9
44 #define PKG_MAX_LEN                                                             128
45 #define VERSION_MAX_LEN                                         128
46 #define DIRECTORY_PERMISSION_755        0755
47 #define DIRECTORY_PERMISSION_644        0644
48 #define FILE_PERMISSION_644                             0644
49
50 #define PERM_BASE                                                                       (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH) // 0644
51 #define PERM_EXECUTE                                                    (S_IXUSR | S_IXGRP | S_IXOTH)
52 #define PERM_WRITE                                                              (S_IWUSR | S_IWGRP | S_IWOTH)
53 #define DIR_PERMS                                                                       (S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)
54
55 #define TEMP_DIR                                                                                                        "/opt/usr/rpminstaller"
56 #define USR_APPS                                                                                                        "/usr/apps"
57 #define OPT_USR                                                                                                         "/opt/usr"
58 #define OPT_USR_APPS                                                                                    "/opt/usr/apps"
59 #define USR_SHARE_PACKAGES                                                              "/usr/share/packages"
60 #define OPT_SHARE_PACKAGES                                                              "/opt/share/packages"
61 #define USR_PACKAGES                                                                            "/usr/packages"
62 #define OPT_STORAGE_SDCARD                                                              "/opt/storage/sdcard"
63 #define OPT_STORAGE_SDCARD_APP_ROOT                             "/opt/storage/sdcard/apps"
64 #define CSC_FLAG                                                                                                        "/opt/usr/data/pkgmgr/csc"
65 #define BIN_DIR_STR                                                                                             "bin"
66 #define RES_DIR_STR                                                                                             "res"
67 #define SHARED_RES_DIR_STR                                                              "shared/res"
68
69 #define PRELOAD_WATCH_FACE_PATH                                         "/usr/apps/com.samsung.watchface"
70
71 #define CORETPK_XML                                                                                             "tizen-manifest.xml"
72 #define RES_XML                                                                         "res/res.xml"
73
74 #ifdef _APPFW_FEATURE_DELTA_UPDATE
75 #define DELTATPK_XML                                                    "delta_info.xml"
76 #define DELTA_EXTENSION                                 ".delta"
77 #endif
78 #define SIGNATURE1_XML                                                                          "signature1.xml"
79 #define SIGNATURE2_XML                                                                          "signature2.xml"
80 #define AUTHOR_SIGNATURE_XML                                                    "author-signature.xml"
81 #define CONFIG_XML                                                                                              "config.xml"
82
83 #define INI_VALUE_SIGNATURE                                                             "signature"
84 #define INI_VALUE_AUTHOR_SIGNATURE                              "author-signature"
85 #define RDS_DELTA_FILE                                                                          ".rds_delta"
86 #define RDS_DELTA_ADD                                                                                   "#add"
87 #define RDS_DELTA_DELETE                                                                        "#delete"
88 #define RDS_DELTA_MODIFY                                                                        "#modify"
89
90 // coretpk
91 static const int VERSION_ERROR = -1;
92 static const int VERSION_OLD = 0;
93 static const int VERSION_SAME = 1;
94 static const int VERSION_NEW = 2;
95
96 #define CORETPK_CATEGORY_CONVERTER                              "/usr/bin/coretpk_category_converter.sh"
97 #define CORETPK_CONFIG_PATH                                                             "/usr/etc/coretpk-installer-config.ini"
98
99 #define CORETPK_INSTALL                                                                         "coretpk-install"
100 #define CORETPK_UNINSTALL                                                                       "coretpk-uninstall"
101 #define CORETPK_DIRECTORY_INSTALL                                       "coretpk-directory-install"
102 #ifdef _APPFW_FEATURE_DELTA_UPDATE
103 #define CORETPK_DELTA_INSTALL                                   "coretpk-delta-install"
104 #endif
105 #ifdef _APPFW_FEATURE_DELTA_UPDATE
106 #define CORETPK_MOUNT_INSTALL                                   "coretpk-mount-install"
107 #endif
108 #define CORETPK_MOVE                                                                                    "coretpk-move"
109 #define CORETPK_REINSTALL                                                                       "coretpk-reinstall"
110 #ifdef _APPFW_FEATURE_EXPANSION_PKG_INSTALL
111 #define CORETPK_TEP_INSTALL                                                                     "coretpk-tep-install"
112 #endif
113
114 // rpm
115 #define PRE_CHECK_FOR_MANIFEST
116 #define CPIO_SCRIPT                                                                                             "/usr/bin/cpio_rpm_package.sh"
117 #define CPIO_SCRIPT_UPDATE_XML                                          "/usr/bin/cpio_rpm_package_update_xml.sh"
118 #define RPM_UPDATE_XML                                                                          "/usr/bin/rpm_update_xml.sh"
119 #define INSTALL_SCRIPT                                                                          "/usr/bin/install_rpm_package.sh"
120 #define INSTALL_SCRIPT_WITH_DBPATH_RO                   "/usr/bin/install_rpm_package_with_dbpath_ro.sh"
121 #define INSTALL_SCRIPT_WITH_DBPATH_RW                   "/usr/bin/install_rpm_package_with_dbpath_rw.sh"
122 #define UNINSTALL_SCRIPT                                                                        "/usr/bin/uninstall_rpm_package.sh"
123 #define UPGRADE_SCRIPT                                                                          "/usr/bin/upgrade_rpm_package.sh"
124 #define UPGRADE_SCRIPT_WITH_DBPATH_RO                   "/usr/bin/upgrade_rpm_package_with_dbpath_ro.sh"
125 #define UPGRADE_SCRIPT_WITH_DBPATH_RW                   "/usr/bin/upgrade_rpm_package_with_dbpath_rw.sh"
126 #define OPT_ZIP_FILE                                                                                    "/usr/system/RestoreDir/opt.zip"
127 #define LIBAIL_PATH                                                                                             "/usr/lib/libail.so.0"
128 #define PKGMGR_DB                                                                                                       "/opt/dbspace/.pkgmgr_parser.db"
129 #define RPM_CONFIG_PATH                                                                         "/usr/etc/rpm-installer-config.ini"
130
131 #define TEMP_DBPATH                                                                                                             "/opt/usr/rpmdb_tmp"
132 #define SMACK_RULES_ALT_PATH                                                                    "/etc/smack/accesses2.d"
133 #define RPM                                                                                                                                             "/usr/etc/package-manager/backend/rpm"
134 #define RPM_UNZIP                                                                                                                       "/usr/bin/unzip"
135 #define DIR_RPM_WGT_SMACK_RULE_OPT                                              "/opt/usr/.wgt/"
136
137 #define PKGTYPE_RPM                                                                                     "rpm"
138 #define PKGTYPE_TPK                                                                                     "tpk"
139 #define TOKEN_PACKAGE_STR                                               "package="
140 #define TOKEN_PATH_STR                                                  "path="
141 #define TOKEN_OPERATION_STR                                     "op="
142 #define TOKEN_REMOVE_STR                                                "removable="
143 #define SEPERATOR_END                                                           ':'
144 #define SEPERATOR_START                                                 '"'
145 #define EXT_APPDATA_PRIVILEGE_NAME      "http://tizen.org/privilege/externalstorage.appdata"
146
147 enum rds_state_type {
148         RDS_STATE_NONE,
149         RDS_STATE_DELETE,
150         RDS_STATE_ADD,
151         RDS_STATE_MODIFY,
152 };
153
154 enum rpm_sig_type {
155         SIG_AUTH,
156         SIG_DIST1,
157         SIG_DIST2,
158 };
159
160 enum rpm_sig_sub_type {
161         SIG_SIGNER,
162         SIG_INTERMEDIATE,
163         SIG_ROOT,
164 };
165
166 enum rpm_privilege_level {
167     PRIVILEGE_UNKNOWN  = 0,
168     PRIVILEGE_PUBLIC   = 1,
169     PRIVILEGE_PARTNER  = 2,
170     PRIVILEGE_PLATFORM = 3
171 };
172
173 typedef struct cert_chain_t {
174         int cert_type;
175         char *cert_value;
176 } cert_chain;
177
178 typedef struct pkginfo_t {
179         char package_name[PKG_MAX_LEN];
180         char version[VERSION_MAX_LEN];
181         char client_id[PKG_MAX_LEN];
182         char api_version[BUF_SIZE];
183         char sig_capath[BUF_SIZE];
184         bool is_widget;
185         bool is_preload;
186         bool support_disable;
187         GList *privileges;
188         pkgmgrinfo_install_location install_location;
189 } pkginfo;
190
191 typedef struct privilegeinfo_t {
192         char package_id[PKG_MAX_LEN];
193         int visibility;
194         GList *privileges;
195 } privilegeinfo;
196
197 typedef struct cmdinfo_t {
198         bool support_disable;
199 } cmdinfo;
200
201 cert_chain list[MAX_CERT_NUM];
202
203 #ifdef _APPFW_FEATURE_DELTA_UPDATE
204 typedef struct delta_info_t{
205         pkginfo *pkg_info;
206         GList *add_files_list;
207         GList *remove_files_list;
208         GList *modify_files_list;
209 }delta_info;
210 #endif
211
212 // Error number according to Tizen Native Package Manager Command Specification v1.0
213 #define RPM_INSTALLER_SUCCESS                                                                                   0
214
215 // 1 -100 : Package command errors
216 #define RPM_INSTALLER_ERR_PKG_NOT_FOUND                                                                 1
217 #define RPM_INSTALLER_ERR_NO_RPM_FILE                                                                   2
218 #define RPM_INSTALLER_ERR_PACKAGE_INVALID                                                               3
219 #define RPM_INSTALLER_ERR_NOT_SUPPORTED_API_VERSION                                             5
220 #define RPM_INSTALLER_ERR_NO_MANIFEST                                                                   11
221 #define RPM_INSTALLER_ERR_INVALID_MANIFEST                                                              12
222 #define RPM_INSTALLER_ERR_SIG_NOT_FOUND                                                                 21
223 #define RPM_INSTALLER_ERR_SIG_INVALID                                                                   22
224 #define RPM_INSTALLER_ERR_SIG_VERIFICATION_FAILED                                               23
225 #define RPM_INSTALLER_ERR_ROOT_CERT_NOT_FOUND                                                   31
226 #define RPM_INSTALLER_ERR_CERT_INVALID                                                                  32
227 #define RPM_INSTALLER_ERR_CERTCHAIN_VERIFICATION_FAILED                                 33
228 #define RPM_INSTALLER_ERR_NO_CONFIG                                                                             34
229 #define RPM_INSTALLER_ERR_INVALID_CONFIG                                                                35
230 #define RPM_INSTALLER_ERR_CMD_NOT_SUPPORTED                                                             36
231 #define RPM_INSTALLER_ERR_CERTIFICATE_EXPIRED                                                   37
232 #define RPM_INSTALLER_ERR_PRIVILEGE_UNAUTHORIZED                                                43
233 #define RPM_INSTALLER_ERR_PRIVILEGE_UNKNOWN                                                             44
234 #define RPM_INSTALLER_ERR_PRIVILEGE_USING_LEGACY_FAILED                                 45
235 #define RPM_INSTALLER_ERR_NOT_ENOUGH_MEMORY                                                             63
236 #define RPM_INSTALLER_ERR_WRONG_PARAM                                                                   64
237 #define RPM_INSTALLER_ERR_SIGNATURE_INVALID_CERT_CHAIN                                  71
238 #define RPM_INSTALLER_ERR_SIGNATURE_INVALID_DISTRIBUTOR_CERT                    72
239 #define RPM_INSTALLER_ERR_SIGNATURE_INVALID_SDK_DEFAULT_AUTHOR_CERT             73
240 #define RPM_INSTALLER_ERR_SIGNATURE_IN_DISTRIBUTOR_CASE_AUTHOR_CERT             74
241 #define RPM_INSTALLER_ERR_SIGNATURE_INVALID_DEVICE_UNIQUE_ID                    75
242 #define RPM_INSTALLER_ERR_SIGNATURE_INVALID_CERT_TIME                                   76
243 #define RPM_INSTALLER_ERR_SIGNATURE_INVALID_NO_HASH_FILE                                77
244 #define RPM_INSTALLER_ERR_SIGNATURE_NO_DEVICE_PROFILE                                   78
245 #define RPM_INSTALLER_ERR_SIGNATURE_INVALID_HASH_SIGNATURE                              79
246
247 // 101-120 : reserved for Core installer
248 #define RPM_INSTALLER_ERR_UNZIP_FAILED                                                                  101
249 #define RPM_INSTALLER_ERR_DBUS_PROBLEM                                                                  102
250 #define RPM_INSTALLER_ERR_PACKAGE_NOT_INSTALLED                                                 104
251 #define RPM_INSTALLER_ERR_RESOURCE_BUSY                                                                 105
252 #define RPM_INSTALLER_ERR_NOT_SUPPOTED_VERSION                                                  107
253 #define RPM_INSTALLER_ERR_DB_ACCESS_FAILED                                                              109
254 #define RPM_INSTALLER_ERR_RPM_OPERATION_FAILED                                                  110
255 #define RPM_INSTALLER_ERR_PACKAGE_NOT_UPGRADED                                                  111
256 #define RPM_INSTALLER_ERR_RPM_SCRIPT_WRONG_ARGS                                                 112
257 #define RPM_INSTALLER_ERR_NEED_USER_CONFIRMATION                                                113
258 #define RPM_INSTALLER_ERR_PACKAGE_INSTALLATION_DISABLED                                 114
259 #define RPM_INSTALLER_ERR_PACKAGE_UNINSTALLATION_DISABLED                               115
260 #define RPM_INSTALLER_ERR_CLEAR_DATA_FAILED                                                             116
261 #define RPM_INSTALLER_ERR_INTERNAL                                                                              117
262 #define RPM_INSTALLER_ERR_UNKNOWN                                                                               119
263 #define RPM_INSTALLER_ERR_PACKAGE_EXIST                                                                 121
264
265
266 #define RPM_INSTALLER_SUCCESS_STR                                                                               "Success"
267 #define RPM_INSTALLER_ERR_WRONG_PARAM_STR                                                               "Wrong Input Param"
268 #define RPM_INSTALLER_ERR_DBUS_PROBLEM_STR                                                              "DBUS Error"
269 #define RPM_INSTALLER_ERR_NOT_ENOUGH_MEMORY_STR                                                 "Not Enough Memory"
270 #define RPM_INSTALLER_ERR_PACKAGE_EXIST_STR                                                             "Package Already Installed"
271 #define RPM_INSTALLER_ERR_PACKAGE_NOT_INSTALLED_STR                                             "Package Not Installed"
272 #define RPM_INSTALLER_ERR_RESOURCE_BUSY_STR                                                             "Resource Busy"
273 #define RPM_INSTALLER_ERR_UNKNOWN_STR                                                                   "Unknown Error"
274 #define RPM_INSTALLER_ERR_PKG_NOT_FOUND_STR                                                             "Package file not found"
275 #define RPM_INSTALLER_ERR_NOT_SUPPOTED_VERSION_STR                                              "Version Not supported"
276 #define RPM_INSTALLER_ERR_NO_RPM_FILE_STR                                                               "No RPM Package"
277 #define RPM_INSTALLER_ERR_DB_ACCESS_FAILED_STR                                                  "DB Access Failed"
278 #define RPM_INSTALLER_ERR_RPM_OPERATION_FAILED_STR                                              "RPM operation failed"
279 #define RPM_INSTALLER_ERR_PACKAGE_NOT_UPGRADED_STR                                              "Package Not Upgraded"
280 #define RPM_INSTALLER_ERR_RPM_SCRIPT_WRONG_ARGS_STR                                             "Wrong Args to Script"
281 #define RPM_INSTALLER_ERR_PACKAGE_INSTALLATION_DISABLED_STR                             "Installation Disabled"
282 #define RPM_INSTALLER_ERR_PACKAGE_UNINSTALLATION_DISABLED_STR                   "Uninstallation Disabled"
283 #define RPM_INSTALLER_ERR_CLEAR_DATA_FAILED_STR                                                 "Clear Data Failed"
284 #define RPM_INSTALLER_ERR_INTERNAL_STR                                                                  "Internal Error"
285 #define RPM_INSTALLER_ERR_NO_MANIFEST_STR                                                               "Manifest File Not Found"
286 #define RPM_INSTALLER_ERR_INVALID_MANIFEST_STR                                                  "Manifest Validation Failed"
287 #define RPM_INSTALLER_ERR_SIG_NOT_FOUND_STR                                                             "Signature Not Found"
288 #define RPM_INSTALLER_ERR_SIG_INVALID_STR                                                               "Invalid Signature"
289 #define RPM_INSTALLER_ERR_SIG_VERIFICATION_FAILED_STR                                   "Signature Verification Failed"
290 #define RPM_INSTALLER_ERR_ROOT_CERT_NOT_FOUND_STR                                               "Root Cert Not Found"
291 #define RPM_INSTALLER_ERR_CERT_INVALID_STR                                                              "Invalid Certificate"
292 #define RPM_INSTALLER_ERR_CERTCHAIN_VERIFICATION_FAILED_STR                             "Certificate Chain Verification Failed"
293 #define RPM_INSTALLER_ERR_NO_CONFIG_STR                                                                 "Config file is not present"
294 #define RPM_INSTALLER_ERR_INVALID_CONFIG_STR                                                    "Config file is not valid"
295 #define RPM_INSTALLER_ERR_CMD_NOT_SUPPORTED_STR                                                 "Unsupported Command"
296 #define RPM_INSTALLER_ERR_PRIVILEGE_UNAUTHORIZED_STR                                    "Unauthorized privilege"
297 #define RPM_INSTALLER_ERR_PRIVILEGE_UNKNOWN_ERR_STR                                             "Unknown privilege"
298 #define RPM_INSTALLER_ERR_PRIVILEGE_USING_LEGACY_FAILED_STR                             "Deprecated privilege"
299 #define RPM_INSTALLER_ERR_NOT_SUPPORTED_API_VERSION_STR                                 "API Version Not supported"
300 #define RPM_INSTALLER_ERR_CERTIFICATE_EXPIRED_STR                                               "Cert Expired"
301 #define RPM_INSTALLER_ERR_UNZIP_FAILED_STR                                                              "Unzip Failed"
302 #define RPM_INSTALLER_ERR_PACKAGE_INVALID_STR                                                   "Package Invalid"
303
304 #define ASCII(s)                (const char *)s
305 #define XMLCHAR(s)      (const xmlChar *)s
306
307 #ifndef FREE_AND_STRDUP
308 #define FREE_AND_STRDUP(from, to) do {  \
309                 if (to) free((void *)to);       \
310                 if (from) to = strdup(from);    \
311 } while(0)
312 #endif
313
314 #ifndef FREE_AND_NULL
315 #define FREE_AND_NULL(ptr) do { \
316                 if (ptr) {      \
317                         free((void *)ptr);      \
318                         ptr = NULL;     \
319                 } \
320 } while(0)
321 #endif
322
323 #define _LOGE(fmt, arg...) do { \
324         fprintf(stderr, "  ## "fmt"\n", ##arg); \
325         LOGE(fmt, ##arg);       \
326 } while(0)
327
328 #define _LOGD(fmt, arg...) do { \
329         fprintf(stderr, "  ## "fmt"\n", ##arg); \
330         LOGD(fmt, ##arg);       \
331 } while(0)
332
333 #define ret_if(expr) do {       \
334         if (expr) {     \
335                 _LOGE("(%s) ", #expr);  \
336                 return; \
337         }       \
338 } while(0)
339
340 #define retm_if(expr, fmt, arg...) do { \
341         if (expr) {     \
342                 _LOGE("(%s) "fmt, #expr, ##arg);        \
343                 return; \
344         }       \
345 } while(0)
346
347 #define retv_if(expr, val) do { \
348         if (expr) {     \
349                 _LOGE("(%s) ", #expr);  \
350                 return (val);   \
351         }       \
352 } while(0)
353
354 #define retvm_if(expr, val, fmt, arg...) do {   \
355         if (expr) {     \
356                 _LOGE("(%s) "fmt, #expr, ##arg);        \
357                 return (val);   \
358         }       \
359 } while(0)
360
361 #define tryvm_if(expr, val, fmt, arg...) do {   \
362         if (expr) {     \
363                 _LOGE("(%s) "fmt, #expr, ##arg);        \
364                 val;    \
365                 goto catch;     \
366         }       \
367 } while(0)
368
369
370 #ifdef __cplusplus
371 }
372 #endif
373 #endif  /* _INSTALLER_TYPE_H_ */