tizen 2.4 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 #ifdef _APPFW_FEATURE_MOUNT_INSTALL
70 #define MIC_ENV                                                                                                 "/tmp/alaunch/-2"
71 #define PKG_NAME_STRING_LEN_MAX                                                         128
72 #endif
73
74 #define PRELOAD_WATCH_FACE_PATH                                         "/usr/apps/com.samsung.watchface"
75
76 #define CORETPK_XML                                                                                             "tizen-manifest.xml"
77 #define RES_XML                                                                         "res/res.xml"
78
79 #ifdef _APPFW_FEATURE_DELTA_UPDATE
80 #define DELTATPK_XML                                                    "delta_info.xml"
81 #define DELTA_EXTENSION                                 ".delta"
82 #endif
83 #define SIGNATURE1_XML                                                                          "signature1.xml"
84 #define SIGNATURE2_XML                                                                          "signature2.xml"
85 #define AUTHOR_SIGNATURE_XML                                                    "author-signature.xml"
86 #define CONFIG_XML                                                                                              "config.xml"
87
88 #define INI_VALUE_SIGNATURE                                                             "signature"
89 #define INI_VALUE_AUTHOR_SIGNATURE                              "author-signature"
90 #define RDS_DELTA_FILE                                                                          ".rds_delta"
91 #define RDS_DELTA_ADD                                                                                   "#add"
92 #define RDS_DELTA_DELETE                                                                        "#delete"
93 #define RDS_DELTA_MODIFY                                                                        "#modify"
94
95 // coretpk
96 static const int VERSION_ERROR = -1;
97 static const int VERSION_OLD = 0;
98 static const int VERSION_SAME = 1;
99 static const int VERSION_NEW = 2;
100
101 #define CORETPK_CATEGORY_CONVERTER                              "/usr/bin/coretpk_category_converter.sh"
102 #define CORETPK_CONFIG_PATH                                                             "/usr/etc/coretpk-installer-config.ini"
103
104 #define CORETPK_INSTALL                                                                         "coretpk-install"
105 #define CORETPK_UNINSTALL                                                                       "coretpk-uninstall"
106 #define CORETPK_DIRECTORY_INSTALL                                       "coretpk-directory-install"
107 #ifdef _APPFW_FEATURE_DELTA_UPDATE
108 #define CORETPK_DELTA_INSTALL                                   "coretpk-delta-install"
109 #endif
110 #ifdef _APPFW_FEATURE_MOUNT_INSTALL
111 #define CORETPK_MOUNT_INSTALL                                   "coretpk-mount-install"
112 #endif
113 #define CORETPK_MOVE                                                                                    "coretpk-move"
114 #define CORETPK_REINSTALL                                                                       "coretpk-reinstall"
115 #ifdef _APPFW_FEATURE_EXPANSION_PKG_INSTALL
116 #define CORETPK_TEP_INSTALL                                                                     "coretpk-tep-install"
117 #endif
118
119 // rpm
120 #define PRE_CHECK_FOR_MANIFEST
121 #define CPIO_SCRIPT                                                                                             "/usr/bin/cpio_rpm_package.sh"
122 #define CPIO_SCRIPT_UPDATE_XML                                          "/usr/bin/cpio_rpm_package_update_xml.sh"
123 #define RPM_UPDATE_XML                                                                          "/usr/bin/rpm_update_xml.sh"
124 #define INSTALL_SCRIPT                                                                          "/usr/bin/install_rpm_package.sh"
125 #define INSTALL_SCRIPT_WITH_DBPATH_RO                   "/usr/bin/install_rpm_package_with_dbpath_ro.sh"
126 #define INSTALL_SCRIPT_WITH_DBPATH_RW                   "/usr/bin/install_rpm_package_with_dbpath_rw.sh"
127 #define UNINSTALL_SCRIPT                                                                        "/usr/bin/uninstall_rpm_package.sh"
128 #define UPGRADE_SCRIPT                                                                          "/usr/bin/upgrade_rpm_package.sh"
129 #define UPGRADE_SCRIPT_WITH_DBPATH_RO                   "/usr/bin/upgrade_rpm_package_with_dbpath_ro.sh"
130 #define UPGRADE_SCRIPT_WITH_DBPATH_RW                   "/usr/bin/upgrade_rpm_package_with_dbpath_rw.sh"
131 #define OPT_ZIP_FILE                                                                                    "/usr/system/RestoreDir/opt.zip"
132 #define LIBAIL_PATH                                                                                             "/usr/lib/libail.so.0"
133 #define PKGMGR_DB                                                                                                       "/opt/dbspace/.pkgmgr_parser.db"
134 #define RPM_CONFIG_PATH                                                                         "/usr/etc/rpm-installer-config.ini"
135
136 #define TEMP_DBPATH                                                                                                             "/opt/usr/rpmdb_tmp"
137 #define SMACK_RULES_ALT_PATH                                                                    "/etc/smack/accesses2.d"
138 #define RPM                                                                                                                                             "/usr/etc/package-manager/backend/rpm"
139 #define RPM_UNZIP                                                                                                                       "/usr/bin/unzip"
140 #define DIR_RPM_WGT_SMACK_RULE_OPT                                              "/opt/usr/.wgt/"
141
142 #define PKGTYPE_RPM                                                                                     "rpm"
143 #define PKGTYPE_TPK                                                                                     "tpk"
144 #define TOKEN_PACKAGE_STR                                               "package="
145 #define TOKEN_PATH_STR                                                  "path="
146 #define TOKEN_OPERATION_STR                                     "op="
147 #define TOKEN_REMOVE_STR                                                "removable="
148 #define SEPERATOR_END                                                           ':'
149 #define SEPERATOR_START                                                 '"'
150 #define EXT_APPDATA_PRIVILEGE_NAME      "http://tizen.org/privilege/externalstorage.appdata"
151
152 enum rds_state_type {
153         RDS_STATE_NONE,
154         RDS_STATE_DELETE,
155         RDS_STATE_ADD,
156         RDS_STATE_MODIFY,
157 };
158
159 enum rpm_sig_type {
160         SIG_AUTH,
161         SIG_DIST1,
162         SIG_DIST2,
163 };
164
165 enum rpm_sig_sub_type {
166         SIG_SIGNER,
167         SIG_INTERMEDIATE,
168         SIG_ROOT,
169 };
170
171 enum rpm_privilege_level {
172     PRIVILEGE_UNKNOWN  = 0,
173     PRIVILEGE_PUBLIC   = 1,
174     PRIVILEGE_PARTNER  = 2,
175     PRIVILEGE_PLATFORM = 3
176 };
177
178 typedef struct cert_chain_t {
179         int cert_type;
180         char *cert_value;
181 } cert_chain;
182
183 typedef struct pkginfo_t {
184         char package_name[PKG_MAX_LEN];
185         char version[VERSION_MAX_LEN];
186         char client_id[PKG_MAX_LEN];
187         char api_version[BUF_SIZE];
188         char sig_capath[BUF_SIZE];
189         char pkg_chksum[BUF_SIZE];
190         bool is_widget;
191         bool is_preload;
192         bool support_disable;
193         GList *privileges;
194         pkgmgrinfo_install_location install_location;
195 } pkginfo;
196
197 typedef struct privilegeinfo_t {
198         char package_id[PKG_MAX_LEN];
199         int visibility;
200         GList *privileges;
201 } privilegeinfo;
202
203 typedef struct cmdinfo_t {
204         bool support_disable;
205         char pkg_chksum[BUF_SIZE];
206 } cmdinfo;
207
208 cert_chain list[MAX_CERT_NUM];
209
210 #ifdef _APPFW_FEATURE_DELTA_UPDATE
211 typedef struct delta_info_t{
212         pkginfo *pkg_info;
213         GList *add_files_list;
214         GList *remove_files_list;
215         GList *modify_files_list;
216 }delta_info;
217 #endif
218
219 // Error number according to Tizen Native Package Manager Command Specification v1.0
220 #define RPM_INSTALLER_SUCCESS                                                                                   0
221
222 // 1 -100 : Package command errors
223 #define RPM_INSTALLER_ERR_PKG_NOT_FOUND                                                                 1
224 #define RPM_INSTALLER_ERR_NO_RPM_FILE                                                                   2
225 #define RPM_INSTALLER_ERR_PACKAGE_INVALID                                                               3
226 #define RPM_INSTALLER_ERR_NOT_SUPPORTED_API_VERSION                                             5
227 #define RPM_INSTALLER_ERR_NO_MANIFEST                                                                   11
228 #define RPM_INSTALLER_ERR_INVALID_MANIFEST                                                              12
229 #define RPM_INSTALLER_ERR_SIG_NOT_FOUND                                                                 21
230 #define RPM_INSTALLER_ERR_SIG_INVALID                                                                   22
231 #define RPM_INSTALLER_ERR_SIG_VERIFICATION_FAILED                                               23
232 #define RPM_INSTALLER_ERR_ROOT_CERT_NOT_FOUND                                                   31
233 #define RPM_INSTALLER_ERR_CERT_INVALID                                                                  32
234 #define RPM_INSTALLER_ERR_CERTCHAIN_VERIFICATION_FAILED                                 33
235 #define RPM_INSTALLER_ERR_NO_CONFIG                                                                             34
236 #define RPM_INSTALLER_ERR_INVALID_CONFIG                                                                35
237 #define RPM_INSTALLER_ERR_CMD_NOT_SUPPORTED                                                             36
238 #define RPM_INSTALLER_ERR_CERTIFICATE_EXPIRED                                                   37
239 #define RPM_INSTALLER_ERR_PRIVILEGE_UNAUTHORIZED                                                43
240 #define RPM_INSTALLER_ERR_PRIVILEGE_UNKNOWN                                                             44
241 #define RPM_INSTALLER_ERR_PRIVILEGE_USING_LEGACY_FAILED                                 45
242 #define RPM_INSTALLER_ERR_NOT_ENOUGH_MEMORY                                                             63
243 #define RPM_INSTALLER_ERR_WRONG_PARAM                                                                   64
244 #define RPM_INSTALLER_ERR_SIGNATURE_INVALID_CERT_CHAIN                                  71
245 #define RPM_INSTALLER_ERR_SIGNATURE_INVALID_DISTRIBUTOR_CERT                    72
246 #define RPM_INSTALLER_ERR_SIGNATURE_INVALID_SDK_DEFAULT_AUTHOR_CERT             73
247 #define RPM_INSTALLER_ERR_SIGNATURE_IN_DISTRIBUTOR_CASE_AUTHOR_CERT             74
248 #define RPM_INSTALLER_ERR_SIGNATURE_INVALID_DEVICE_UNIQUE_ID                    75
249 #define RPM_INSTALLER_ERR_SIGNATURE_INVALID_CERT_TIME                                   76
250 #define RPM_INSTALLER_ERR_SIGNATURE_INVALID_NO_HASH_FILE                                77
251 #define RPM_INSTALLER_ERR_SIGNATURE_NO_DEVICE_PROFILE                                   78
252 #define RPM_INSTALLER_ERR_SIGNATURE_INVALID_HASH_SIGNATURE                              79
253
254 // 101-120 : reserved for Core installer
255 #define RPM_INSTALLER_ERR_UNZIP_FAILED                                                                  101
256 #define RPM_INSTALLER_ERR_DBUS_PROBLEM                                                                  102
257 #define RPM_INSTALLER_ERR_PACKAGE_NOT_INSTALLED                                                 104
258 #define RPM_INSTALLER_ERR_RESOURCE_BUSY                                                                 105
259 #define RPM_INSTALLER_ERR_NOT_SUPPOTED_VERSION                                                  107
260 #define RPM_INSTALLER_ERR_DB_ACCESS_FAILED                                                              109
261 #define RPM_INSTALLER_ERR_RPM_OPERATION_FAILED                                                  110
262 #define RPM_INSTALLER_ERR_PACKAGE_NOT_UPGRADED                                                  111
263 #define RPM_INSTALLER_ERR_RPM_SCRIPT_WRONG_ARGS                                                 112
264 #define RPM_INSTALLER_ERR_NEED_USER_CONFIRMATION                                                113
265 #define RPM_INSTALLER_ERR_PACKAGE_INSTALLATION_DISABLED                                 114
266 #define RPM_INSTALLER_ERR_PACKAGE_UNINSTALLATION_DISABLED                               115
267 #define RPM_INSTALLER_ERR_CLEAR_DATA_FAILED                                                             116
268 #define RPM_INSTALLER_ERR_INTERNAL                                                                              117
269 #define RPM_INSTALLER_ERR_UNKNOWN                                                                               119
270 #define RPM_INSTALLER_ERR_PACKAGE_EXIST                                                                 121
271
272
273 #define RPM_INSTALLER_SUCCESS_STR                                                                               "Success"
274 #define RPM_INSTALLER_ERR_WRONG_PARAM_STR                                                               "Wrong Input Param"
275 #define RPM_INSTALLER_ERR_DBUS_PROBLEM_STR                                                              "DBUS Error"
276 #define RPM_INSTALLER_ERR_NOT_ENOUGH_MEMORY_STR                                                 "Not Enough Memory"
277 #define RPM_INSTALLER_ERR_PACKAGE_EXIST_STR                                                             "Package Already Installed"
278 #define RPM_INSTALLER_ERR_PACKAGE_NOT_INSTALLED_STR                                             "Package Not Installed"
279 #define RPM_INSTALLER_ERR_RESOURCE_BUSY_STR                                                             "Resource Busy"
280 #define RPM_INSTALLER_ERR_UNKNOWN_STR                                                                   "Unknown Error"
281 #define RPM_INSTALLER_ERR_PKG_NOT_FOUND_STR                                                             "Package file not found"
282 #define RPM_INSTALLER_ERR_NOT_SUPPOTED_VERSION_STR                                              "Version Not supported"
283 #define RPM_INSTALLER_ERR_NO_RPM_FILE_STR                                                               "No RPM Package"
284 #define RPM_INSTALLER_ERR_DB_ACCESS_FAILED_STR                                                  "DB Access Failed"
285 #define RPM_INSTALLER_ERR_RPM_OPERATION_FAILED_STR                                              "RPM operation failed"
286 #define RPM_INSTALLER_ERR_PACKAGE_NOT_UPGRADED_STR                                              "Package Not Upgraded"
287 #define RPM_INSTALLER_ERR_RPM_SCRIPT_WRONG_ARGS_STR                                             "Wrong Args to Script"
288 #define RPM_INSTALLER_ERR_PACKAGE_INSTALLATION_DISABLED_STR                             "Installation Disabled"
289 #define RPM_INSTALLER_ERR_PACKAGE_UNINSTALLATION_DISABLED_STR                   "Uninstallation Disabled"
290 #define RPM_INSTALLER_ERR_CLEAR_DATA_FAILED_STR                                                 "Clear Data Failed"
291 #define RPM_INSTALLER_ERR_INTERNAL_STR                                                                  "Internal Error"
292 #define RPM_INSTALLER_ERR_NO_MANIFEST_STR                                                               "Manifest File Not Found"
293 #define RPM_INSTALLER_ERR_INVALID_MANIFEST_STR                                                  "Manifest Validation Failed"
294 #define RPM_INSTALLER_ERR_SIG_NOT_FOUND_STR                                                             "Signature Not Found"
295 #define RPM_INSTALLER_ERR_SIG_INVALID_STR                                                               "Invalid Signature"
296 #define RPM_INSTALLER_ERR_SIG_VERIFICATION_FAILED_STR                                   "Signature Verification Failed"
297 #define RPM_INSTALLER_ERR_ROOT_CERT_NOT_FOUND_STR                                               "Root Cert Not Found"
298 #define RPM_INSTALLER_ERR_CERT_INVALID_STR                                                              "Invalid Certificate"
299 #define RPM_INSTALLER_ERR_CERTCHAIN_VERIFICATION_FAILED_STR                             "Certificate Chain Verification Failed"
300 #define RPM_INSTALLER_ERR_NO_CONFIG_STR                                                                 "Config file is not present"
301 #define RPM_INSTALLER_ERR_INVALID_CONFIG_STR                                                    "Config file is not valid"
302 #define RPM_INSTALLER_ERR_CMD_NOT_SUPPORTED_STR                                                 "Unsupported Command"
303 #define RPM_INSTALLER_ERR_PRIVILEGE_UNAUTHORIZED_STR                                    "Unauthorized privilege"
304 #define RPM_INSTALLER_ERR_PRIVILEGE_UNKNOWN_ERR_STR                                             "Unknown privilege"
305 #define RPM_INSTALLER_ERR_PRIVILEGE_USING_LEGACY_FAILED_STR                             "Deprecated privilege"
306 #define RPM_INSTALLER_ERR_NOT_SUPPORTED_API_VERSION_STR                                 "API Version Not supported"
307 #define RPM_INSTALLER_ERR_CERTIFICATE_EXPIRED_STR                                               "Cert Expired"
308 #define RPM_INSTALLER_ERR_UNZIP_FAILED_STR                                                              "Unzip Failed"
309 #define RPM_INSTALLER_ERR_PACKAGE_INVALID_STR                                                   "Package Invalid"
310
311 #define ASCII(s)                (const char *)s
312 #define XMLCHAR(s)      (const xmlChar *)s
313
314 #ifndef FREE_AND_STRDUP
315 #define FREE_AND_STRDUP(from, to) do {  \
316                 if (to) free((void *)to);       \
317                 if (from) to = strdup(from);    \
318 } while(0)
319 #endif
320
321 #ifndef FREE_AND_NULL
322 #define FREE_AND_NULL(ptr) do { \
323                 if (ptr) {      \
324                         free((void *)ptr);      \
325                         ptr = NULL;     \
326                 } \
327 } while(0)
328 #endif
329
330 #define _LOGE(fmt, arg...) do { \
331         fprintf(stderr, "  ## "fmt"\n", ##arg); \
332         LOGE(fmt, ##arg);       \
333 } while(0)
334
335 #define _LOGD(fmt, arg...) do { \
336         fprintf(stderr, "  ## "fmt"\n", ##arg); \
337         LOGD(fmt, ##arg);       \
338 } while(0)
339
340 #define _SLOGE(fmt, arg...) do {        \
341         fprintf(stderr, "  ## "fmt"\n", ##arg); \
342         SECURE_LOGE(fmt, ##arg);        \
343 } while(0)
344
345 #define _SLOGD(fmt, arg...) do {        \
346         fprintf(stderr, "  ## "fmt"\n", ##arg); \
347         SECURE_LOGD(fmt, ##arg);        \
348 } while(0)
349
350 #define ret_if(expr) do {       \
351         if (expr) {     \
352                 _LOGE("(%s) ", #expr);  \
353                 return; \
354         }       \
355 } while(0)
356
357 #define retm_if(expr, fmt, arg...) do { \
358         if (expr) {     \
359                 _LOGE("(%s) "fmt, #expr, ##arg);        \
360                 return; \
361         }       \
362 } while(0)
363
364 #define retv_if(expr, val) do { \
365         if (expr) {     \
366                 _LOGE("(%s) ", #expr);  \
367                 return (val);   \
368         }       \
369 } while(0)
370
371 #define retvm_if(expr, val, fmt, arg...) do {   \
372         if (expr) {     \
373                 _LOGE("(%s) "fmt, #expr, ##arg);        \
374                 return (val);   \
375         }       \
376 } while(0)
377
378 #define tryvm_if(expr, val, fmt, arg...) do {   \
379         if (expr) {     \
380                 _LOGE("(%s) "fmt, #expr, ##arg);        \
381                 val;    \
382                 goto catch;     \
383         }       \
384 } while(0)
385
386
387 #ifdef __cplusplus
388 }
389 #endif
390 #endif  /* _INSTALLER_TYPE_H_ */