--- /dev/null
+#
+# Copyright (c) 2008 ~ 2010 Samsung Electronics Co., Ltd.
+# All rights reserved
+#
+
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+SET(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true)
+
+PROJECT(rpm-installer C)
+
+SET(PREFIX ${CMAKE_INSTALL_PREFIX})
+SET(EXEC_PREFIX "\${prefix}")
+SET(LIBDIR "\${prefix}/lib")
+SET(INCLUDEDIR "\${prefix}/include")
+SET(VERSION 1.0)
+
+set(CMAKE_SKIP_BUILD_RPATH true)
+
+configure_file(rpm_installer_deactvation_list.txt.in rpm_installer_deactvation_list.txt @ONLY)
+INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/rpm_installer_deactvation_list.txt DESTINATION /opt/share/packages/.pkgmgr/rpm-installer/)
+
+##################
+## build comm libraries
+add_subdirectory(common)
+add_subdirectory(frontend)
+add_subdirectory(po)
+add_subdirectory(backend-lib)
+##################
+
--- /dev/null
+Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ 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.
+
--- /dev/null
+#
+# Copyright (c) 2008 ~ 2010 Samsung Electronics Co., Ltd.
+# All rights reserved
+#
+
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+set(CMAKE_SKIP_BUILD_RPATH true)
+
+#Verbose
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/inc ${CMAKE_CURRENT_SOURCE_DIR}/inc )
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(pkgs REQUIRED dbus-glib-1 pkgmgr-types vconf)
+#pkg_check_modules(pkgs REQUIRED pkgmgr-installer-status-broadcast-server security-server vconf sqlite3 dbus-glib-1 glib-2.0 db-util )
+
+FOREACH(flag ${pkgs_CFLAGS})
+ SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+pkg_check_modules(libpkgs REQUIRED dbus-glib-1 pkgmgr-types vconf)
+
+FOREACH(flag ${libpkgs_CFLAGS})
+ SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+pkg_check_modules(STATUS pkgmgr-installer-status-broadcast-server pkgmgr-types vconf)
+
+link_directories ("${STATUS_LIBRARY_DIRS} /usr/lib")
+include_directories (${STATUS_INCLUDE_DIRS})
+find_library(RPM_LIBRARY rpm "/usr/lib")
+
+SET(backend_lib_dir "${CMAKE_CURRENT_SOURCE_DIR}")
+SET(backend_lib_inc_dir "${backend_lib_dir}/inc")
+SET(backend_lib_c_src_dir "${backend_lib_dir}/src")
+
+## Additional flag
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden")
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -g -Wall")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
+###################################################################################################
+## for backend_lib (binary)
+SET(backend_lib_SOURCES ${backend_lib_c_src_dir}/librpminternals.c ${backend_lib_c_src_dir}/librpm.c)
+SET(backend_lib_CFLAGS " -I. -I/usr/include/rpm -I${backend_lib_inc_dir} ${pkg_CFLAGS}")
+SET(backend_lib_LDFLAGS ${pkgs_LDFLAGS})
+
+ADD_LIBRARY(nativerpm SHARED ${backend_lib_SOURCES})
+#TARGET_LINK_LIBRARIES(nativerpm ${RPM_LIB})
+TARGET_LINK_LIBRARIES(nativerpm "rpm")
+SET_TARGET_PROPERTIES(nativerpm PROPERTIES COMPILE_FLAGS "${backend_lib_CFLAGS}")
+####################################################################################################
+
+INSTALL(TARGETS nativerpm DESTINATION lib COMPONENT RuntimeLibraries)
+
+####################################################################################################
--- /dev/null
+/*
+ * rpm-installer
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
+ * Jaeho Lee <jaeho81.lee@samsung.com>, Shobhit Srivastava <shobhit.s@samsung.com>
+ *
+ * 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 <package-manager-plugin.h>
+#include <unistd.h>
+#include <vconf.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <dirent.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+#define API __attribute__ ((visibility("default")))
+#define DEBUG_ERR 0x0001
+#define DEBUG_INFO 0x0002
+#define DEBUG_RESULT 0x0004
+#define LIBRPM_LOG 1
+#define LIBRPM_SUCCESS 0
+#define LIBRPM_ERROR -1
+
+#define BLOCK_SIZE 4096 /*in bytes*/
+#define LIKELY(expr) __builtin_expect((expr), 1)
+#define UNLIKELY(expr) __builtin_expect((expr), 0)
+
+void _librpm_print_msg(int type, int exetype, char *format, ...);
+#define _librpm_print(type, fmtstr, args...) { \
+_librpm_print_msg(type, LIBRPM_LOG, "%s():%d: " fmtstr, \
+__func__, __LINE__, ##args); \
+}
+
+int _librpm_get_package_header_info(const char *pkg_path,
+ package_manager_pkg_detail_info_t *pkg_detail_info);
+int _librpm_get_installed_package_info(const char *pkgid,
+ package_manager_pkg_detail_info_t *pkg_detail_info);
+int _librpm_app_is_installed(const char *pkgid);
+long long _librpm_calculate_dir_size(const char *dirname);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
--- /dev/null
+/*
+ * rpm-installer
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
+ * Jaeho Lee <jaeho81.lee@samsung.com>, Shobhit Srivastava <shobhit.s@samsung.com>
+ *
+ * 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 <stdio.h>
+#include <string.h>
+#include <sys/time.h>
+/*rpm specific headers*/
+#include <rpmlib.h>
+#include <header.h>
+#include <rpmts.h>
+#include <rpmdb.h>
+#include <vconf.h>
+
+#include "librpminternals.h"
+
+#define BASEDIR "/opt/share"
+#define BUFFSIZE 256
+
+void pkg_native_plugin_on_unload(void)
+{
+ return;
+}
+
+int pkg_plugin_app_is_installed(const char *pkgid)
+{
+ _librpm_print(DEBUG_INFO,
+ "pkg_plugin_app_is_installed() is called\n");
+ /* Check for valid arguments */
+ if (pkgid == NULL) {
+ _librpm_print(DEBUG_ERR,
+ "[pkg_plugin_get_app_detail_info_from_package] "
+ "args supplied is NULL\n");
+ return LIBRPM_ERROR;
+ }
+ int ret = -1;
+ ret = _librpm_app_is_installed(pkgid);
+ if (ret == -1) {
+ _librpm_print(DEBUG_ERR, "_librpm_app_is_installed() failed\n");
+ return LIBRPM_ERROR;
+ }
+ /*1 for installed, 0 for not installed*/
+ if (ret == 1)
+ return LIBRPM_SUCCESS;
+ else
+ return LIBRPM_ERROR;
+}
+
+int pkg_plugin_get_installed_apps_list(const char *category,
+ const char *option,
+ package_manager_pkg_info_t **list,
+ int *count)
+{
+ return LIBRPM_SUCCESS;
+}
+
+int pkg_plugin_get_app_detail_info(const char *pkgid,
+ package_manager_pkg_detail_info_t
+ *pkg_detail_info)
+{
+ _librpm_print(DEBUG_INFO,
+ "pkg_plugin_get_app_detail_info() is called\n");
+ /* Check for valid arguments */
+ if (pkgid == NULL || pkg_detail_info == NULL) {
+ _librpm_print(DEBUG_ERR,
+ "[pkg_plugin_get_app_detail_info_from_package] "
+ "args supplied is NULL\n");
+ return LIBRPM_ERROR;
+ }
+ char dirname[BUFFSIZE] = { '\0' };
+ int ret = 0;
+ long long data_size = 0;
+ char buff[256] = {'\0'};
+ time_t install_time = 0;
+
+ /* pkgtype is by default rpm */
+ strncpy(pkg_detail_info->pkg_type, "rpm", sizeof(pkg_detail_info->pkg_type));
+
+ /* Get the installed package info from rpm db */
+ ret = _librpm_get_installed_package_info(pkgid, pkg_detail_info);
+ if (ret) {
+ return LIBRPM_ERROR;
+ }
+
+ /*get data_size*/
+ snprintf(dirname, BUFFSIZE-1, "/opt/usr/apps/%s/data", pkgid);
+ data_size = _librpm_calculate_dir_size(dirname);
+ if (data_size < 0) {
+ _librpm_print(DEBUG_ERR,
+ "Calculate dir size failed\n");
+ pkg_detail_info->data_size = 0 ;
+ }
+ else {
+ data_size += BLOCK_SIZE; /* the function does not adds 4096
+ bytes for the directory size itself*/
+ pkg_detail_info->data_size = data_size/1024 ;
+ }
+
+ /* Min Platform Version */
+ pkg_detail_info->min_platform_version[0] = '\0';
+
+ /* Optional ID*/
+ pkg_detail_info->optional_id[0] = '\0';
+
+ /* Total Installed Size*/
+ pkg_detail_info->installed_size = pkg_detail_info->app_size +
+ pkg_detail_info->data_size;
+ /* Installed Time*/
+ snprintf(buff, 256, "db/app-info/%s/installed-time", pkgid);
+ ret = vconf_get_int(buff, (int *)&install_time);
+ if (ret) {
+ _librpm_print(DEBUG_ERR, "get installed time failed\n");
+ pkg_detail_info->installed_time = 0;
+ }
+ else
+ pkg_detail_info->installed_time = install_time;
+
+
+ return LIBRPM_SUCCESS;
+}
+
+int pkg_plugin_get_app_detail_info_from_package(const char *pkg_path,
+ package_manager_pkg_detail_info_t
+ *pkg_detail_info)
+{
+ _librpm_print(DEBUG_INFO,
+ "pkg_plugin_get_app_detail_info_from_package() is called\n");
+
+ /* Check for valid arguments */
+ if (pkg_path == NULL || pkg_detail_info == NULL) {
+ _librpm_print(DEBUG_ERR,
+ "[pkg_plugin_get_app_detail_info_from_package]"
+ "args supplied is NULL\n");
+ return LIBRPM_ERROR;
+ }
+
+ int ret = 0;
+ long long data_size = 0;
+ char *str = NULL;
+ char dirname[BUFFSIZE] = { '\0' };
+ char buff[256] = {'\0'};
+ time_t install_time = 0;
+
+ /* populate pkg type */
+ str = strrchr(pkg_path, 46); /* 46 is ASCII for . */
+ strncpy(pkg_detail_info->pkg_type, (str + 1), strlen(str + 1));
+
+ /* populate rpm header specific info (name, version, description, size)*/
+ ret = _librpm_get_package_header_info(pkg_path, pkg_detail_info);
+ if (ret) {
+ return LIBRPM_ERROR;
+ }
+
+ /*get data_size. If pkg is not installed it will be 0*/
+ snprintf(dirname, BUFFSIZE-1, "/opt/usr/apps/%s/data",
+ pkg_detail_info->pkgid);
+
+ data_size = _librpm_calculate_dir_size(dirname);
+ if (data_size < 0) {
+ _librpm_print(DEBUG_ERR,
+ "Calculate dir size failed\n");
+ pkg_detail_info->data_size = 0 ;
+ }
+ else {
+ data_size += BLOCK_SIZE; /* the function does not adds 4096
+ bytes for the directory size itself*/
+
+ pkg_detail_info->data_size = data_size/1024 ;
+ }
+
+ /* Min Platform Version */
+ pkg_detail_info->min_platform_version[0] = '\0';
+
+ /* Optional ID*/
+ pkg_detail_info->optional_id[0] = '\0';
+
+ /* Total Installed Size*/
+ pkg_detail_info->installed_size = pkg_detail_info->app_size +
+ pkg_detail_info->data_size;
+
+ /* Installed Time */
+ snprintf(buff, 256, "db/app-info/%s/installed-time", pkg_detail_info->pkgid);
+ ret = vconf_get_int(buff, (int *)&install_time);
+ if (ret) {
+ _librpm_print(DEBUG_ERR, "get installed time failed\n");
+ pkg_detail_info->installed_time = 0;
+ }
+ else
+ pkg_detail_info->installed_time = install_time;
+
+
+ return LIBRPM_SUCCESS;
+}
+
+API int pkg_plugin_on_load(pkg_plugin_set *set)
+{
+ _librpm_print(DEBUG_ERR, "pkg_plugin_on_load() is called\n");
+ static int initialized = 0;
+ rpmRC rc;
+ if (set == NULL) {
+ return LIBRPM_ERROR;
+ }
+
+ memset(set, 0x00, sizeof(pkg_plugin_set));
+ if (!initialized) {
+ rc = rpmReadConfigFiles(NULL, NULL);
+ if (rc == RPMRC_OK) {
+ initialized = 1;
+ _librpm_print(DEBUG_ERR, "Successfully read RPM configuration.\n");
+ }
+ else {
+ _librpm_print(DEBUG_ERR, "Unable to read RPM configuration.\n");
+ initialized = 0;
+ return LIBRPM_ERROR;
+ }
+ }
+
+ set->plugin_on_unload = pkg_native_plugin_on_unload;
+ set->pkg_is_installed = pkg_plugin_app_is_installed;
+ set->get_installed_pkg_list = pkg_plugin_get_installed_apps_list;
+ set->get_pkg_detail_info = pkg_plugin_get_app_detail_info;
+ set->get_pkg_detail_info_from_package =
+ pkg_plugin_get_app_detail_info_from_package;
+
+ return LIBRPM_SUCCESS;
+}
--- /dev/null
+/*
+ * rpm-installer
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
+ * Jaeho Lee <jaeho81.lee@samsung.com>, Shobhit Srivastava <shobhit.s@samsung.com>
+ *
+ * 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 <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <stdarg.h>
+#include <unistd.h>
+#include <sys/wait.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <regex.h>
+#include <dlog.h>
+/*rpm specific headers*/
+#include <rpmlib.h>
+#include <header.h>
+#include <rpmts.h>
+#include <rpmdb.h>
+#include <rpmlog.h>
+#include "librpminternals.h"
+
+/* This is backend lib's filter string for dlogutil*/
+#define LOCAL_LOG_TAG "librpm"
+int logging = 0x0004;
+#ifdef LOG_IN_FILE
+#define RPM_INSTALLER_LIBRPM_LOG_FILE "/tmp/librpm"
+FILE *logfile = NULL;
+#endif
+
+void _librpm_print_msg(int type, int exetype, char *format, ...)
+{
+ char buffer[FILENAME_MAX] = { 0 };
+ char tbuffer[FILENAME_MAX] = { 0 };
+
+ va_list args;
+ va_start(args, format);
+ vsnprintf(tbuffer, FILENAME_MAX, format, args);
+ va_end(args);
+
+ switch (type) {
+ case DEBUG_ERR:
+ LOG(LOG_ERROR, LOCAL_LOG_TAG, "%s", tbuffer);
+ break;
+ case DEBUG_RESULT:
+ LOG(LOG_WARN, LOCAL_LOG_TAG, "%s", tbuffer);
+ break;
+ case DEBUG_INFO:
+ LOG(LOG_DEBUG, LOCAL_LOG_TAG, "%s", tbuffer);
+ default:
+ break;
+ }
+
+ if (logging == 0)
+ return;
+
+ if (DEBUG_ERR == (logging & type)) {
+ snprintf(buffer, FILENAME_MAX, "ERROR:%s", tbuffer);
+ vfprintf(stderr, format, args);
+ } else if (DEBUG_INFO == (logging & type)) {
+ snprintf(buffer, FILENAME_MAX, "INFO:%s", tbuffer);
+ vfprintf(stdout, format, args);
+ } else if (DEBUG_RESULT == (logging & type)) {
+ snprintf(buffer, FILENAME_MAX, "RESULT:%s", tbuffer);
+ vfprintf(stdout, format, args);
+ } else {
+ return;
+ }
+
+#ifdef LOG_IN_FILE
+ if (logfile != NULL)
+ fwrite(buffer, sizeof(char), strlen(buffer), logfile);
+#endif /*LOG_IN_FILE */
+}
+
+int _librpm_app_is_installed(const char *pkgid)
+{
+ rpmts ts = NULL;
+ int ret = 0;
+ int found = 0;
+ rpmdbMatchIterator mi;
+
+ ts = rpmtsCreate();
+ mi = rpmtsInitIterator(ts, RPMTAG_NAME, pkgid, 0);
+ while (NULL != rpmdbNextIterator(mi)) {
+ found = 1;
+ }
+
+ if (found == 0) {
+ _librpm_print(DEBUG_INFO, "Package not found in DB\n");
+ ret = 0;
+ goto err;
+ }
+ else {
+ _librpm_print(DEBUG_INFO, "Package found in DB\n");
+ ret = 1;
+ goto err;
+ }
+err:
+ rpmtsFree(ts);
+ rpmdbFreeIterator(mi);
+ return ret;
+}
+
+int _librpm_get_installed_package_info(const char *pkgid,
+ package_manager_pkg_detail_info_t *pkg_detail_info)
+{
+ rpmts ts = NULL;
+ Header hdr = NULL;
+ int found = 0;
+ int ret = 0;
+ rpmdbMatchIterator mi;
+ rpmtd td, tn, tv, ta;
+
+ td = rpmtdNew();
+ tn = rpmtdNew();
+ tv = rpmtdNew();
+ ta = rpmtdNew();
+ ts = rpmtsCreate();
+
+ mi = rpmtsInitIterator(ts, RPMTAG_NAME, pkgid, 0);
+ while (NULL != (hdr = rpmdbNextIterator(mi))) {
+ hdr = headerLink(hdr);
+ found = 1;
+ break;
+ }
+
+ /*Print the header info */
+ if (found == 0) {
+ _librpm_print(DEBUG_ERR, "Package not found in DB\n");
+ ret = LIBRPM_ERROR;
+ goto err;
+ }
+ /*Name*/
+ headerGet(hdr, RPMTAG_NAME, tn, HEADERGET_MINMEM);
+ strncpy(pkg_detail_info->pkgid, rpmtdGetString(tn), PKG_NAME_STRING_LEN_MAX-1);
+ /*Version*/
+ headerGet(hdr, RPMTAG_VERSION, tv, HEADERGET_MINMEM);
+ strncpy(pkg_detail_info->version, rpmtdGetString(tv), PKG_VERSION_STRING_LEN_MAX-1);
+ /*Description*/
+ headerGet(hdr, RPMTAG_DESCRIPTION, td, HEADERGET_MINMEM);
+ strncpy(pkg_detail_info->pkg_description, rpmtdGetString(td), PKG_VALUE_STRING_LEN_MAX-1);
+ /*Size*/
+ headerGet(hdr, RPMTAG_SIZE, ta, HEADERGET_MINMEM);
+ pkg_detail_info->app_size = rpmtdGetNumber(ta);
+ ret = LIBRPM_SUCCESS;
+
+err:
+ headerFree(hdr);
+ rpmtdFreeData(tn);
+ rpmtdFree(tn);
+ rpmtdFreeData(td);
+ rpmtdFree(td);
+ rpmtdFreeData(ta);
+ rpmtdFree(ta);
+ rpmtdFreeData(tv);
+ rpmtdFree(tv);
+ rpmdbFreeIterator(mi);
+ rpmtsFree(ts);
+
+ return ret;
+
+}
+
+int _librpm_get_package_header_info(const char *pkg_path,
+ package_manager_pkg_detail_info_t *pkg_detail_info)
+{
+ int ret = 0;
+ rpmts ts = NULL;
+ rpmtd td = NULL;
+ FD_t fd;
+ rpmRC rc;
+ Header hdr = NULL;
+ rpmVSFlags vsflags = 0;
+
+ fd = Fopen(pkg_path, "r.ufdio");
+ if ((!fd) || Ferror(fd)) {
+ _librpm_print(DEBUG_ERR, "Failed to open package file (%s)\n", Fstrerror(fd));
+ ret = LIBRPM_ERROR;
+ goto err;
+ }
+
+ ts = rpmtsCreate();
+ td = rpmtdNew();
+ hdr = headerNew();
+
+ vsflags |= _RPMVSF_NODIGESTS;
+ vsflags |= _RPMVSF_NOSIGNATURES;
+ vsflags |= RPMVSF_NOHDRCHK;
+ (void) rpmtsSetVSFlags(ts, vsflags);
+
+ rc = rpmReadPackageFile(ts, fd, pkg_path, &hdr);
+ if (rc != RPMRC_OK) {
+ _librpm_print(DEBUG_ERR, "Could not read package file\n");
+ ret = LIBRPM_ERROR;
+ goto err;
+ }
+ Fclose(fd);
+ /*Name*/
+ headerGet(hdr, RPMTAG_NAME, td, HEADERGET_MINMEM);
+ strncpy(pkg_detail_info->pkgid, rpmtdGetString(td), PKG_NAME_STRING_LEN_MAX-1);
+ rpmtdReset(td);
+ /*Version*/
+ headerGet(hdr, RPMTAG_VERSION, td, HEADERGET_MINMEM);
+ strncpy(pkg_detail_info->version, rpmtdGetString(td), PKG_VERSION_STRING_LEN_MAX-1);
+ rpmtdReset(td);
+ /*Description*/
+ headerGet(hdr, RPMTAG_DESCRIPTION, td, HEADERGET_MINMEM);
+ strncpy(pkg_detail_info->pkg_description, rpmtdGetString(td), PKG_VALUE_STRING_LEN_MAX-1);
+ rpmtdReset(td);
+ /*Size*/
+ headerGet(hdr, RPMTAG_SIZE, td, HEADERGET_MINMEM);
+ pkg_detail_info->app_size = rpmtdGetNumber(td);
+
+ ret = LIBRPM_SUCCESS;
+err:
+ rpmtdFreeData(td);
+ rpmtdFree(td);
+ headerFree(hdr);
+ rpmtsFree(ts);
+ return ret;
+
+}
+
+long long _librpm_calculate_dir_size(const char *dirname)
+{
+ long long total = 0;
+ long long ret = 0;
+ int q = 0; /*quotient*/
+ int r = 0; /*remainder*/
+ DIR *dp = NULL;
+ struct dirent *ep = NULL;
+ struct stat fileinfo;
+ char abs_filename[FILENAME_MAX] = { 0, };
+ if (dirname == NULL) {
+ _librpm_print(DEBUG_ERR,
+ "dirname is NULL");
+ return LIBRPM_ERROR;
+ }
+ dp = opendir(dirname);
+ if (dp != NULL) {
+ while ((ep = readdir(dp)) != NULL) {
+ if (!strcmp(ep->d_name, ".") ||
+ !strcmp(ep->d_name, "..")) {
+ continue;
+ }
+ snprintf(abs_filename, FILENAME_MAX, "%s/%s", dirname,
+ ep->d_name);
+ if (stat(abs_filename, &fileinfo) < 0)
+ perror(abs_filename);
+ else {
+ if (S_ISDIR(fileinfo.st_mode)) {
+ total += fileinfo.st_size;
+ if (strcmp(ep->d_name, ".")
+ && strcmp(ep->d_name, "..")) {
+ ret = _librpm_calculate_dir_size
+ (abs_filename);
+ total = total + ret;
+ }
+ } else {
+ /*It is a file. Calculate the actual
+ size occupied (in terms of 4096 blocks)*/
+ q = (fileinfo.st_size / BLOCK_SIZE);
+ r = (fileinfo.st_size % BLOCK_SIZE);
+ if (r) {
+ q = q + 1;
+ }
+ total += q * BLOCK_SIZE;
+ }
+ }
+ }
+ (void)closedir(dp);
+ } else {
+ _librpm_print(DEBUG_ERR,
+ "Couldn't open the directory\n");
+ return -1;
+ }
+ return total;
+
+}
--- /dev/null
+/*
+ * rpm-installer
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
+ * Jaeho Lee <jaeho81.lee@samsung.com>, Shobhit Srivastava <shobhit.s@samsung.com>
+ *
+ * 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.
+ *
+ */
+
+#ifndef __RPM_INSTALLER_SIGNATURE_H_
+#define __RPM_INSTALLER_SIGNATURE_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+typedef struct transform_x {
+ const char *algorithm;
+ struct transform_x *prev;
+ struct transform_x *next;
+} transform_x;
+
+typedef struct digestmethod_x {
+ const char *algorithm;
+ struct digestmethod_x *prev;
+ struct digestmethod_x *next;
+} digestmethod_x;
+
+typedef struct digestvalue_x {
+ const char *text;
+ struct digestvalue_x *prev;
+ struct digestvalue_x *next;
+} digestvalue_x;
+
+typedef struct transforms_x {
+ struct transform_x *transform;
+ struct transforms_x *prev;
+ struct transforms_x *next;
+} transforms_x;
+
+typedef struct x509certificate_x {
+ const char *text;
+ struct x509certificate_x *prev;
+ struct x509certificate_x *next;
+} x509certificate_x;
+
+typedef struct reference_x {
+ const char *uri;
+ struct transforms_x *transforms;
+ struct digestmethod_x *digestmethod;
+ struct digestvalue_x *digestvalue;
+ struct reference_x *prev;
+ struct reference_x *next;
+} reference_x;
+
+typedef struct cannonicalizationmethod_x {
+ const char *algorithm;
+ struct cannonicalizationmethod_x *prev;
+ struct cannonicalizationmethod_x *next;
+} cannonicalizationmethod_x;
+
+typedef struct signaturemethod_x {
+ const char *algorithm;
+ struct signaturemethod_x *prev;
+ struct signaturemethod_x *next;
+} signaturemethod_x;
+
+typedef struct x509data_x {
+ x509certificate_x *x509certificate;
+ struct x509data_x *prev;
+ struct x509data_x *next;
+} x509data_x;
+
+typedef struct signedinfo_x {
+ struct cannonicalizationmethod_x *cannonicalizationmethod;
+ struct signaturemethod_x *signaturemethod;
+ struct reference_x *reference;
+ struct signedinfo_x *prev;
+ struct signedinfo_x *next;
+} signedinfo_x;
+
+typedef struct signaturevalue_x {
+ const char *text;
+ struct signaturevalue_x *prev;
+ struct signaturevalue_x *next;
+} signaturevalue_x;
+
+typedef struct keyinfo_x {
+ struct x509data_x *x509data;
+ struct keyinfo_x *prev;
+ struct keyinfo_x *next;
+} keyinfo_x;
+
+/*This will be parsed later when requirement arises*/
+typedef struct object_x {
+ const char *id;
+ struct object_x *prev;
+ struct object_x *next;
+} object_x;
+
+typedef struct signature_x { /*signature xml*/
+ const char *id; /* distributor or author sign*/
+ const char *xmlns; /* namespace*/
+ struct signedinfo_x *signedinfo; /*signature data*/
+ struct signaturevalue_x *signaturevalue; /* signature value*/
+ struct keyinfo_x *keyinfo; /*cert info*/
+ struct object_x *object; /*other parameters in object tag*/
+} signature_x;
+
+
+signature_x *_ri_process_signature_xml(const char *signature_file);
+void _ri_free_signature_xml(signature_x *sigx);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+#endif /* __RPM_INSTALLER_SIGNATURE_H_ */
--- /dev/null
+/*
+ * rpm-installer
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
+ * Jaeho Lee <jaeho81.lee@samsung.com>, Shobhit Srivastava <shobhit.s@samsung.com>
+ *
+ * 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.
+ *
+ */
+
+#ifndef __RPM_INSTALLER_H_
+#define __RPM_INSTALLER_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+#include "rpm-installer-util.h"
+#include <stdbool.h>
+
+#define PM_UNLIKELY(expr) __builtin_expect((expr), 0)
+#define PM_LIKELY(expr) __builtin_expect((expr), 1)
+
+ enum backend_state {
+ REQUEST_ACCEPTED = 1,
+ GOT_PACKAGE_INFO_SUCCESSFULLY,
+ REQUEST_PENDING,
+ REQUEST_COMPLETED
+ };
+ typedef enum backend_state backend_state;
+ struct pkginfo_t {
+ char package_name[128];
+ char version[11];
+ };
+
+ typedef struct pkginfo_t pkginfo;
+
+/**
+ * Install the package
+ * @in :pkgfilepath : Package file path
+ * @in :force_install: Whether we need to forceful overwrite.
+ * If package already installed then reinstall the application
+ * @in :install_options: install options
+ */
+ int _rpm_installer_package_install(char *pkgfilepath,
+ bool force_install,
+ char *install_options);
+
+/**
+ * Install the package
+ * @in :pkgfilepath : Package file path
+ */
+ int _rpm_installer_package_install_with_dbpath(char *pkgfilepath);
+
+/**
+ * Install the package manifest
+ * @in :pkgfilepath : Package manifest file path
+ */
+ int _rpm_installer_corexml_install(char *pkgfilepath);
+/**
+ * get the package information from package name
+ * return the package information
+ * @in :pkgid : package id for which information is requested
+ */
+ pkginfo *_rpm_installer_get_pkgname_info(char *pkgid);
+
+/**
+ * get the package information from package file
+ * return the package information
+ * @in :pkgfile : package file for which information is requested
+ */
+ pkginfo *_rpm_installer_get_pkgfile_info(char *pkgfile);
+
+/**
+ * Uninstall the Application
+ * @in :pkgid : package id to be uninstalled
+ */
+ int _rpm_installer_package_uninstall(char *pkgid);
+
+/**
+ * Uninstall the Application
+ * @in :pkgid : package id to be uninstalled
+ */
+ int _rpm_installer_package_uninstall_with_dbpath(char *pkgid);
+
+/* Dbus related prototype */
+ void _ri_broadcast_status_notification(char *pkgid, char *key,
+ char *val);
+ int _rpm_backend_interface(char *keyid, char *pkgid,
+ char *reqcommand);
+
+/* RPM operations prototype */
+ int _rpm_uninstall_pkg(char *pkgid);
+ int _rpm_install_pkg(char *pkgfilepath, char *installoptions);
+ int _rpm_upgrade_pkg(char *pkgfilepath, char *installoptions);
+
+ int _rpm_install_pkg_with_dbpath(char *pkgfilepath, char *pkgid);
+ int _rpm_upgrade_pkg_with_dbpath(char *pkgfilepath, char *pkgid);
+ int _rpm_uninstall_pkg_with_dbpath(char *pkgid, bool is_system);
+
+ int _rpm_install_corexml(char *pkgfilepath, char *pkgid);
+ int _rpm_process_cscxml(char *xml_path);
+ int _rpm_process_fota(char *fota_script);
+ int _rpm_process_fota_for_rw(char *fota_script);
+
+ int _rpm_process_enable(char *pkgid);
+ int _rpm_process_disable(char *pkgid);
+
+ int _ri_set_backend_state(int state);
+ int _ri_get_backend_state();
+ int _ri_get_backend_state_info();
+ int _ri_set_backend_state_info(int state);
+ int _ri_get_last_input_info(char **pkgid, int *preqcommand,
+ int *poptions);
+ void _ri_save_last_input_info(char *pkgid, int reqcommand,
+ int options);
+ void _ri_package_downgrade_information(const char *message);
+ int _rpm_installer_clear_private_data(char *pkgid);
+ int _rpm_move_pkg(char *pkgid, int move_type);
+
+/* libprivilege-control specific operations prototype*/
+ int _ri_privilege_register_package(const char *pkgid);
+ int _ri_privilege_unregister_package(const char *pkgid);
+ int _ri_privilege_revoke_permissions(const char *pkgid);
+ int _ri_privilege_enable_permissions(const char *pkgid, int apptype,
+ const char **perms, int persistent);
+ int _ri_privilege_setup_path(const char *pkgid, const char *dirpath,
+ int apppathtype, const char *groupid);
+ int _ri_privilege_add_friend(const char *pkgid1, const char *pkgid2);
+ int _ri_privilege_change_smack_label(const char *path, const char *label,
+ int label_type);
+ int _ri_verify_sig_and_cert(const char *sigfile);
+ void _ri_unregister_cert(const char *pkgid);
+ void _ri_register_cert(const char *pkgid);
+ void _ri_apply_smack(char *pkgname, int flag);
+ int _ri_apply_perm(char *pkgid);
+
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+#endif /* __RPM_INSTALLER_H_ */
--- /dev/null
+#!/bin/sh
+PKGFILE_PATH="$1"
+/usr/bin/rpm2cpio "$PKGFILE_PATH" | cpio -idmv find -name *.xml
\ No newline at end of file
--- /dev/null
+#!/bin/sh
+INPUT=$1
+OUTPUT=$2
+if [ -z "$1" ] || [ -z "$2" ]
+then
+ echo "error!"
+ exit 2
+fi
+sed "s#/usr/apps/#/opt/usr/apps/#g" $INPUT > $OUTPUT
--- /dev/null
+#!/bin/sh
+
+E_WRONG_ARGS=17
+E_FILE_NOT_FOUND=11
+E_RPM_ERROR=15
+
+PKG_LOG_DIR=/var/pkgmgr/rpm
+
+
+debug () {
+ /bin/echo ">>$DEBUG" >> /tmp/rpmscriptlog
+}
+
+NOARG=$#
+
+if [ $NOARG -lt 1 ] || [ $NOARG -gt 2 ] ; then
+ DEBUG="Usage: install.sh PKG_FILE";debug
+ exit $E_WRONG_ARGS
+elif [ $NOARG -eq 2 ] ; then
+ OPTIONS_FLAGS=$2
+fi
+PKGFILE_PATH="$1"
+
+if [ ! -f "$1" ];then
+ DEBUG="File not found";debug
+ exit $E_FILE_NOT_FOUND
+fi
+
+if [ ! -d $PKG_LOG_DIR ];then
+ DEBUG="$PKG_LOG_DIR not exist -> mkdir(ok)";debug
+ /bin/mkdir -p $PKG_LOG_DIR
+fi
+
+
+/bin/rpm --install --percent --nodeps $OPTION_FLAGS "$PKGFILE_PATH"
+rpmretval=$?
+if [ $rpmretval -ne 0 ]; then
+ DEBUG="rpm returned error ";debug
+ exit $E_RPM_ERROR
+else
+ DEBUG="rpm success ";debug
+fi
+
--- /dev/null
+#!/bin/sh
+
+E_WRONG_ARGS=17
+E_FILE_NOT_FOUND=11
+E_RPM_ERROR=15
+
+PKG_LOG_DIR=/var/pkgmgr/rpm
+
+
+debug () {
+ /bin/echo ">>$DEBUG" >> /tmp/rpmscriptlog
+}
+
+NOARG=$#
+
+if [ $NOARG -lt 1 ] || [ $NOARG -gt 2 ] ; then
+ DEBUG="Usage: install.sh PKG_FILE";debug
+ exit $E_WRONG_ARGS
+elif [ $NOARG -eq 2 ] ; then
+ OPTIONS_FLAGS=$2
+fi
+PKGFILE_PATH="$1"
+
+if [ ! -f "$1" ];then
+ DEBUG="File not found";debug
+ exit $E_FILE_NOT_FOUND
+fi
+
+if [ ! -d $PKG_LOG_DIR ];then
+ DEBUG="$PKG_LOG_DIR not exist -> mkdir(ok)";debug
+ /bin/mkdir -p $PKG_LOG_DIR
+fi
+
+echo /bin/rpm --install --percent --nodeps --force "$PKGFILE_PATH" --relocate "/usr/apps"="/opt/usr/apps" --relocate "/usr/share"="/opt/usr/rpminstaller" --dbpath="/opt/usr/rpmdb_tmp"
+/bin/rpm --install --percent --nodeps --force "$PKGFILE_PATH" --relocate "/usr/apps"="/opt/usr/apps" --relocate "/usr/share"="/opt/usr/rpminstaller" --dbpath="/opt/usr/rpmdb_tmp"
+rpmretval=$?
+if [ $rpmretval -ne 0 ]; then
+ DEBUG="rpm returned error ";debug
+ exit $E_RPM_ERROR
+else
+ DEBUG="rpm success ";debug
+fi
+
--- /dev/null
+#!/bin/sh
+
+E_WRONG_ARGS=17
+E_FILE_NOT_FOUND=11
+E_RPM_ERROR=15
+
+PKG_LOG_DIR=/var/pkgmgr/rpm
+
+
+debug () {
+ /bin/echo ">>$DEBUG" >> /tmp/rpmscriptlog
+}
+
+NOARG=$#
+
+if [ $NOARG -lt 1 ] || [ $NOARG -gt 2 ] ; then
+ DEBUG="Usage: install.sh PKG_FILE";debug
+ exit $E_WRONG_ARGS
+elif [ $NOARG -eq 2 ] ; then
+ OPTIONS_FLAGS=$2
+fi
+PKGFILE_PATH="$1"
+
+if [ ! -f "$1" ];then
+ DEBUG="File not found";debug
+ exit $E_FILE_NOT_FOUND
+fi
+
+if [ ! -d $PKG_LOG_DIR ];then
+ DEBUG="$PKG_LOG_DIR not exist -> mkdir(ok)";debug
+ /bin/mkdir -p $PKG_LOG_DIR
+fi
+
+echo /bin/rpm --install --percent --nodeps --force "$PKGFILE_PATH" --dbpath="/opt/usr/rpmdb_tmp"
+/bin/rpm --install --percent --nodeps --force "$PKGFILE_PATH" --dbpath="/opt/usr/rpmdb_tmp"
+rpmretval=$?
+if [ $rpmretval -ne 0 ]; then
+ DEBUG="rpm returned error ";debug
+ exit $E_RPM_ERROR
+else
+ DEBUG="rpm success ";debug
+fi
+
--- /dev/null
+#!/bin/sh
+
+RPM_FILE=$1
+OUTPUT=$2
+
+rpm -qp $RPM_FILE --queryformat="[%{POSTIN}\n]" > $OUTPUT
\ No newline at end of file
--- /dev/null
+#!/bin/sh
+E_RPM_NOT_INSTALLED=1
+E_RPM_ALREADY_INSTALLED=2
+E_WRONG_ARGS=17
+E_FILE_NOT_FOUND=11
+
+echo "find pakcage $1" >> /tmp/rpmscriptlog
+
+CURDIR=`pwd`
+echo $CURDIR >> /tmp/rpmscriptlog
+
+debug () {
+ /bin/echo ">>$DEBUG" >> /tmp/rpmscriptlog
+}
+
+if [ $# -ne 1 ];then
+ DEBUG="Usage: query_package.sh PKG_FILE";debug
+ exit $E_WRONG_ARGS
+fi
+
+PKGNAME=$1
+/bin/echo "pkg name = $PKGNAME" >> /tmp/rpmscriptlog
+
+PKG_LOG_DIR=/var/pkgmgr/$PKGNAME
+if [ ! -d $PKG_LOG_DIR ];then
+ DEBUG="$PKG_LOG_DIR not exist -> mkdir(ok)";debug
+ /bin/mkdir -p $PKG_LOG_DIR
+fi
+
+if [ -f $PKGNAME ]; then
+ /bin/rpm -qpi $PKGNAME
+ retval=$?
+else
+ /bin/rpm -qi $PKGNAME
+ retval=$?
+fi
+echo "retval = $retval" >> /tmp/rpmscriptlog
+
+if [ $retval -ne 0 ];then
+ DEBUG="pakcage not exist";debug
+ cd $CURDIR
+ exit $E_RPM_NOT_INSTALLED
+else
+ exit $E_RPM_ALREADY_INSTALLED
+fi
--- /dev/null
+#!/bin/sh
+
+E_WRONG_ARGS=17
+E_FILE_NOT_FOUND=11
+E_RPM_ERROR=15
+
+PKG_LOG_DIR=/var/pkgmgr/rpm
+
+debug () {
+ /bin/echo ">>$DEBUG" >> /tmp/rpmscriptlog
+}
+
+NOARG=$#
+
+if [ $NOARG -lt 1 ] || [ $NOARG -gt 2 ]; then
+ DEBUG="Usage: uninstall.sh <PackageName>";debug
+ exit $E_WRONG_ARGS
+fi
+
+
+if [ ! -d $PKG_LOG_DIR ];then
+ DEBUG="$PKG_LOG_DIR not exist -> mkdir(ok)";debug
+ /bin/mkdir -p $PKG_LOG_DIR
+fi
+
+PKGNAME=$1
+
+# 3. DELETE FILES
+/bin/rpm --erase --nodeps $PKGNAME
+ret=$?
+if [ $ret -ne 0 ];then
+ DEBUG="rpm error";debug
+ exit $E_RPM_ERROR
+fi
--- /dev/null
+#!/bin/sh
+
+E_WRONG_ARGS=17
+E_FILE_NOT_FOUND=11
+E_RPM_ERROR=15
+
+PKG_LOG_DIR=/var/pkgmgr/rpm
+
+
+debug () {
+ /bin/echo ">>$DEBUG" >> /tmp/rpmscriptlog
+}
+
+NOARG=$#
+
+if [ $NOARG -lt 1 ] || [ $NOARG -gt 2 ] ; then
+ DEBUG="Usage: install.sh PKG_FILE";debug
+ exit $E_WRONG_ARGS
+elif [ $NOARG -eq 2 ] ; then
+ OPTIONS_FLAGS=$2
+fi
+PKGFILE_PATH="$1"
+
+if [ ! -f "$1" ];then
+ DEBUG="File not found";debug
+ exit $E_FILE_NOT_FOUND
+fi
+
+if [ ! -d $PKG_LOG_DIR ];then
+ DEBUG="$PKG_LOG_DIR not exist -> mkdir(ok)";debug
+ /bin/mkdir -p $PKG_LOG_DIR
+fi
+
+
+#rpm --upgrade --percent --nodeps --replacepkgs $OPTION_FLAGS "$PKGFILE_PATH"
+/bin/rpm --upgrade --percent --nodeps --replacepkgs --force "$PKGFILE_PATH"
+rpmretval=$?
+if [ $rpmretval -ne 0 ]; then
+ DEBUG="rpm returned error ";debug
+ exit $E_RPM_ERROR
+else
+ DEBUG="rpm success ";debug
+fi
+
--- /dev/null
+#!/bin/sh
+
+E_WRONG_ARGS=17
+E_FILE_NOT_FOUND=11
+E_RPM_ERROR=15
+
+PKG_LOG_DIR=/var/pkgmgr/rpm
+
+
+debug () {
+ /bin/echo ">>$DEBUG" >> /tmp/rpmscriptlog
+}
+
+NOARG=$#
+
+if [ $NOARG -lt 1 ] || [ $NOARG -gt 2 ] ; then
+ DEBUG="Usage: install.sh PKG_FILE";debug
+ exit $E_WRONG_ARGS
+elif [ $NOARG -eq 2 ] ; then
+ OPTIONS_FLAGS=$2
+fi
+PKGFILE_PATH="$1"
+
+if [ ! -f "$1" ];then
+ DEBUG="File not found";debug
+ exit $E_FILE_NOT_FOUND
+fi
+
+if [ ! -d $PKG_LOG_DIR ];then
+ DEBUG="$PKG_LOG_DIR not exist -> mkdir(ok)";debug
+ /bin/mkdir -p $PKG_LOG_DIR
+fi
+
+echo /bin/rpm --upgrade --percent --nodeps --replacepkgs --force "$PKGFILE_PATH" --relocate "/usr/apps"="/opt/usr/apps" --relocate "/usr/share"="/opt/usr/rpminstaller" --dbpath="/opt/usr/rpmdb_tmp"
+/bin/rpm --upgrade --percent --nodeps --replacepkgs --force "$PKGFILE_PATH" --relocate "/usr/apps"="/opt/usr/apps" --relocate "/usr/share"="/opt/usr/rpminstaller" --dbpath="/opt/usr/rpmdb_tmp"
+rpmretval=$?
+if [ $rpmretval -ne 0 ]; then
+ DEBUG="rpm returned error ";debug
+ exit $E_RPM_ERROR
+else
+ DEBUG="rpm success ";debug
+fi
+
--- /dev/null
+#!/bin/sh
+
+E_WRONG_ARGS=17
+E_FILE_NOT_FOUND=11
+E_RPM_ERROR=15
+
+PKG_LOG_DIR=/var/pkgmgr/rpm
+
+
+debug () {
+ /bin/echo ">>$DEBUG" >> /tmp/rpmscriptlog
+}
+
+NOARG=$#
+
+if [ $NOARG -lt 1 ] || [ $NOARG -gt 2 ] ; then
+ DEBUG="Usage: install.sh PKG_FILE";debug
+ exit $E_WRONG_ARGS
+elif [ $NOARG -eq 2 ] ; then
+ OPTIONS_FLAGS=$2
+fi
+PKGFILE_PATH="$1"
+
+if [ ! -f "$1" ];then
+ DEBUG="File not found";debug
+ exit $E_FILE_NOT_FOUND
+fi
+
+if [ ! -d $PKG_LOG_DIR ];then
+ DEBUG="$PKG_LOG_DIR not exist -> mkdir(ok)";debug
+ /bin/mkdir -p $PKG_LOG_DIR
+fi
+
+echo /bin/rpm --upgrade --percent --nodeps --replacepkgs --force "$PKGFILE_PATH" --dbpath="/opt/usr/rpmdb_tmp"
+/bin/rpm --upgrade --percent --nodeps --replacepkgs --force "$PKGFILE_PATH" --dbpath="/opt/usr/rpmdb_tmp"
+rpmretval=$?
+if [ $rpmretval -ne 0 ]; then
+ DEBUG="rpm returned error ";debug
+ exit $E_RPM_ERROR
+else
+ DEBUG="rpm success ";debug
+fi
+
--- /dev/null
+/*
+ * rpm-installer
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
+ * Jaeho Lee <jaeho81.lee@samsung.com>, Shobhit Srivastava <shobhit.s@samsung.com>
+ *
+ * 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.
+ *
+ */
+
+/* System Include files */
+#include <stdbool.h>
+#include <string.h>
+#include <stdlib.h>
+#include <sys/wait.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <wait.h>
+#include <regex.h>
+#include <pthread.h>
+#include <dirent.h>
+#include <fcntl.h>
+#include <errno.h>
+
+/* SLP include files */
+#include <pkgmgr-info.h>
+#include <pkgmgr_parser.h>
+#include "rpm-installer.h"
+#include "rpm-installer-type.h"
+#include "rpm-installer-util.h"
+#include "db-util.h"
+
+#define QUERY_PACKAGE "/usr/bin/query_rpm_package.sh"
+#define RPM_PKG_INFO "/var/rpmpkg.info"
+
+extern char *gpkgname;
+extern int do_upgrade;
+static int __ri_recursive_delete_dir(char *dirname);
+
+static int __ri_recursive_delete_dir(char *dirname)
+{
+ int ret=0;
+ DIR *dp;
+ struct dirent *ep;
+ char abs_filename[FILENAME_MAX];
+ struct stat stFileInfo;
+ dp = opendir(dirname);
+ if (dp != NULL) {
+ while ((ep = readdir(dp))) {
+ snprintf(abs_filename, FILENAME_MAX, "%s/%s", dirname,
+ ep->d_name);
+ if (lstat(abs_filename, &stFileInfo) < 0)
+ perror(abs_filename);
+ if (S_ISDIR(stFileInfo.st_mode)) {
+ if (strcmp(ep->d_name, ".") &&
+ strcmp(ep->d_name, "..")) {
+ ret=__ri_recursive_delete_dir(abs_filename);
+ if(ret < 0)
+ _d_msg(DEBUG_ERR, "__ri_recursive_delete_dir fail\n");
+
+ ret=remove(abs_filename);
+ if(ret < 0)
+ _d_msg(DEBUG_ERR, "remove fail\n");
+ }
+ } else {
+ ret = remove(abs_filename);
+ if(ret < 0)
+ _d_msg(DEBUG_ERR, "Couldn't remove abs_filename\n");
+ }
+ }
+ (void)closedir(dp);
+ } else {
+ _d_msg(DEBUG_ERR, "Couldn't open the directory\n");
+ if (errno == ENOENT)
+ return RPM_INSTALLER_SUCCESS;
+ else
+ return RPM_INSTALLER_ERR_CLEAR_DATA_FAILED;
+ }
+
+ return RPM_INSTALLER_SUCCESS;
+}
+
+int __rpm_xsystem(const char *argv[])
+{
+ int status = 0;
+ pid_t pid;
+ pid = fork();
+ switch (pid) {
+ case -1:
+ perror("fork failed");
+ return -1;
+ case 0:
+ /* child */
+ execvp(argv[0], (char *const *)argv);
+ _exit(-1);
+ default:
+ /* parent */
+ break;
+ }
+ if (waitpid(pid, &status, 0) == -1) {
+ perror("waitpid failed");
+ return -1;
+ }
+ if (WIFSIGNALED(status)) {
+ perror("signal");
+ return -1;
+ }
+ if (!WIFEXITED(status)) {
+ /* shouldn't happen */
+ perror("should not happen");
+ return -1;
+ }
+ return WEXITSTATUS(status);
+}
+
+char* _manifest_to_package(const char* manifest)
+{
+ char *package;
+
+ if(manifest == NULL) {
+ _d_msg(DEBUG_ERR, "manifest is NULL.\n");
+ return NULL;
+ }
+
+ package = strdup(manifest);
+ if(package == NULL) {
+ _d_msg(DEBUG_ERR, "strdup failed.\n");
+ return NULL;
+ }
+
+ if (!strstr(package, ".xml")) {
+ _d_msg(DEBUG_ERR, "%s is not a manifest file\n", manifest);
+ free(package);
+ return NULL;
+ }
+
+ return package;
+}
+
+char* _rpm_load_directory(char *directory)
+{
+ DIR *dir;
+ struct dirent entry, *result;
+ int ret;
+ char *buf = NULL;
+
+ buf = malloc(BUF_SIZE);
+ if (buf == NULL) {
+ _d_msg(DEBUG_ERR, "malloc failed.\n");
+ return NULL;
+ }
+
+ dir = opendir(directory);
+ if (!dir) {
+ if (strerror_r(errno, buf, BUF_SIZE) == 0)
+ _d_msg(DEBUG_ERR, "Can not access to the [%s] because %s.\n", directory, buf);
+ free(buf);
+ return NULL;
+ }
+
+ _d_msg(DEBUG_INFO, "Loading manifest files from %s\n", directory);
+
+ for (ret = readdir_r(dir, &entry, &result);
+ ret == 0 && result != NULL;
+ ret = readdir_r(dir, &entry, &result)) {
+ char *manifest;
+
+ if (!strcmp(entry.d_name, ".") ||
+ !strcmp(entry.d_name, "..")) {
+ continue;
+ }
+
+ manifest = _manifest_to_package(entry.d_name);
+ if (!manifest) {
+ _d_msg(DEBUG_ERR, "Failed to convert file to xml[%s].\n", entry.d_name);
+ continue;
+ }
+
+ snprintf(buf, BUF_SIZE, "%s/%s", directory, manifest);
+ free(manifest);
+ }
+
+ closedir(dir);
+
+ return buf;
+}
+
+int __rpm_delete_dir(char *dirname)
+{
+ int ret = 0;
+ DIR *dp;
+ struct dirent *ep;
+ char abs_filename[FILENAME_MAX];
+ struct stat stFileInfo;
+ dp = opendir(dirname);
+ if (dp != NULL) {
+ while ((ep = readdir(dp))) {
+ snprintf(abs_filename, FILENAME_MAX, "%s/%s", dirname, ep->d_name);
+ if (lstat(abs_filename, &stFileInfo) < 0) {
+ perror(abs_filename);
+ }
+ if (S_ISDIR(stFileInfo.st_mode)) {
+ if (strcmp(ep->d_name, ".") && strcmp(ep->d_name, "..")) {
+ __rpm_delete_dir(abs_filename);
+ (void)remove(abs_filename);
+ }
+ } else {
+ (void)remove(abs_filename);
+ }
+ }
+ (void)closedir(dp);
+ } else {
+ _d_msg(DEBUG_ERR, "Couldn't open the directory\n");
+ return -1;
+ }
+ ret = remove(dirname);
+ if (ret < 0) {
+ _d_msg(DEBUG_ERR, "remove fail dirname[%s]\n", dirname);
+ }
+
+ return 0;
+}
+
+pkginfo *_rpm_installer_get_pkgfile_info(char *pkgfile)
+{
+ pkginfo *info = NULL;
+ manifest_x *mfx = NULL;
+ int ret = 0;
+ int m_exist = 0;
+ char cwd[BUF_SIZE] = {'\0'};
+ char buff[BUF_SIZE] = {'\0'};
+ char manifest[BUF_SIZE] = { '\0'};
+
+ getcwd(cwd, BUF_SIZE);
+ if (cwd[0] == '\0') {
+ _d_msg(DEBUG_ERR, "getcwd() failed.\n");
+ return NULL;
+ }
+
+ ret = mkdir(TEMP_DIR, 0644);
+ if (ret < 0) {
+ if (access(TEMP_DIR, F_OK) == 0) {
+ __rpm_delete_dir(TEMP_DIR);
+ ret = mkdir(TEMP_DIR, 0644);
+ if (ret < 0) {
+ _d_msg(DEBUG_ERR, "mkdir() failed.\n");
+ return NULL;
+ }
+ } else {
+ _d_msg(DEBUG_ERR, "mkdir() failed.\n");
+ return NULL;
+ }
+ }
+
+ ret = chdir(TEMP_DIR);
+ if (ret != 0) {
+ _d_msg(DEBUG_ERR, "chdir(%s) failed [%s].\n", TEMP_DIR, strerror(errno));
+ goto err;
+ }
+
+ _d_msg(DEBUG_INFO, "switched to %s\n", TEMP_DIR);
+
+ const char *cpio_argv[] = { CPIO_SCRIPT, pkgfile, NULL };
+ ret = __rpm_xsystem(cpio_argv);
+
+ snprintf(manifest, BUF_SIZE, "%s/opt/share/packages", TEMP_DIR);
+ char* manifestpath = _rpm_load_directory(manifest);
+ if (manifestpath != NULL) {
+ strncpy(buff, manifestpath, sizeof(buff) - 1);
+ free(manifestpath);
+ }
+
+ if (buff[0] == '\0') {
+ snprintf(manifest, BUF_SIZE, "%s/usr/share/packages", TEMP_DIR);
+ manifestpath = _rpm_load_directory(manifest);
+ if (manifestpath != NULL) {
+ strncpy(buff, manifestpath, sizeof(buff) - 1);
+ free(manifestpath);
+ }
+
+ if (buff[0] == '\0') {
+ goto err;
+ } else {
+ m_exist = 1;
+ }
+ } else {
+ m_exist = 1;
+ }
+
+ if (m_exist) {
+
+ _d_msg(DEBUG_INFO, "The path of manifest.xml is %s.\n", buff);
+
+ info = malloc(sizeof(pkginfo));
+ if (info == NULL) {
+ _d_msg(DEBUG_ERR, "malloc failed.\n");
+ goto err;
+ }
+
+ /*get package name from xml*/
+ mfx = pkgmgr_parser_process_manifest_xml(buff);
+ if (mfx) {
+ strncpy(info->package_name, mfx->package, sizeof(info->package_name) - 1);
+ strncpy(info->version, mfx->version, sizeof(info->version) - 1);
+ _d_msg(DEBUG_INFO, "_rpm_installer_get_pkgfile_info, pkgname: (%s), version(%s)\n", info->package_name, info->version);
+ }
+ pkgmgr_parser_free_manifest_xml(mfx);
+ }
+
+err:
+ __rpm_delete_dir(TEMP_DIR);
+
+ ret = chdir(cwd);
+ if (ret != 0) {
+ _d_msg(DEBUG_ERR, "chdir(%s) failed [%s].\n", cwd, strerror(errno));
+ }
+
+ return info;
+}
+
+pkginfo *_rpm_installer_get_pkgname_info(char *pkgid)
+{
+ pkginfo *info = NULL;
+ int ret = 0;
+ char *packageid = NULL;
+ char *version = NULL;
+ pkgmgrinfo_pkginfo_h handle = NULL;
+
+ if (pkgid == NULL) {
+ _d_msg(DEBUG_ERR, "pkgid is NULL.\n");
+ return NULL;
+ }
+
+ info = malloc(sizeof(pkginfo));
+ if (info == NULL) {
+ _d_msg(DEBUG_ERR, "malloc failed.\n");
+ return NULL;
+ }
+
+ ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle);
+ if (ret != PMINFO_R_OK || &handle == NULL) {
+ _d_msg(DEBUG_ERR, "There is no old version for %s.\n", pkgid);
+ free(info);
+ return NULL;
+ }
+
+ ret = pkgmgrinfo_pkginfo_get_pkgid(handle, &packageid);
+ if (ret != PMINFO_R_OK) {
+ _d_msg(DEBUG_ERR, "Failed to get the pkgid.\n");
+ goto err;
+ }
+ strncpy(info->package_name, packageid, sizeof(info->package_name) - 1);
+
+ ret = pkgmgrinfo_pkginfo_get_version(handle, &version);
+ if (ret != PMINFO_R_OK) {
+ _d_msg(DEBUG_ERR, "Failed to get the version.\n");
+ goto err;
+ }
+ strncpy(info->version, version, sizeof(info->version) - 1);
+
+ pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
+
+ _d_msg(DEBUG_INFO, "_rpm_installer_get_pkgname_info, pkgname: (%s), version(%s)\n", info->package_name, info->version);
+
+ return info;
+
+err:
+ free(info);
+ pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
+ return NULL;
+}
+
+int _rpm_installer_corexml_install(char *pkgfilepath)
+{
+ /* Get package ID from filepath <pkgid.xml>*/
+ char *p = NULL;
+ char *q = NULL;
+ char *temp = NULL;
+ int ret = 0;
+ int idx = 0;
+ temp = strdup(pkgfilepath);
+ if (temp == NULL)
+ return RPM_INSTALLER_ERR_NOT_ENOUGH_MEMORY;
+ p = strrchr(temp, '/');
+ if (p) {
+ p++;
+ } else {
+ free(temp);
+ return RPM_INSTALLER_ERR_INTERNAL;
+ }
+ /*p now points to pkgid.xml*/
+ q = strrchr(p, '.');
+ if (q == NULL) {
+ _d_msg(DEBUG_ERR, "Failed to extract pkgid from xml name\n");
+ free(temp);
+ return RPM_INSTALLER_ERR_INTERNAL;
+ }
+ idx = strlen(p) - strlen(q);
+ p[idx] = '\0';
+ _d_msg(DEBUG_INFO, "Package ID is %s\n", p);
+ ret = _rpm_install_corexml(pkgfilepath, p);
+ free(temp);
+ return ret;
+}
+
+int _rpm_installer_package_install(char *pkgfilepath, bool forceinstall,
+ char *installoptions)
+{
+ int err = 0;
+ char *p = NULL;
+ if (forceinstall == true && installoptions == NULL)
+ return RPM_INSTALLER_ERR_WRONG_PARAM;
+
+ /* Check for core xml installation */
+ p = strrchr(pkgfilepath, '.');
+ if (p) {
+ if (strncmp(p+1, "xml", 3) == 0) {
+ err = _rpm_installer_corexml_install(pkgfilepath);
+ if (err) {
+ _d_msg(DEBUG_ERR, "_rpm_installer_corexml_install() failed\n");
+ } else {
+ _d_msg(DEBUG_ERR, "_rpm_installer_corexml_install() success\n");
+ }
+ return err;
+ }
+ } else {
+ _d_msg(DEBUG_ERR, "pkgfilepath does not have an extension\n");
+ return RPM_INSTALLER_ERR_INTERNAL;
+ }
+ /* rpm installation */
+ pkginfo *info = NULL;
+ pkginfo *tmpinfo = NULL;
+ /*Check to see if the package is already installed or not
+ If it is installed, compare the versions. If the current version
+ is higher than the installed version, upgrade it automatically
+ else ask for user confirmation before downgrading */
+
+ info = _rpm_installer_get_pkgfile_info(pkgfilepath);
+ if (info == NULL) {
+ /* failed to get pkg info */
+ return RPM_INSTALLER_ERR_INTERNAL;
+ }
+
+ _ri_set_backend_state_info(GOT_PACKAGE_INFO_SUCCESSFULLY);
+ if (gpkgname) {
+ free(gpkgname);
+ gpkgname = NULL;
+ }
+ gpkgname = strdup(info->package_name);
+
+ tmpinfo = _rpm_installer_get_pkgname_info(info->package_name);
+ if (tmpinfo == NULL) {
+ _d_msg(DEBUG_INFO, "tmpinfo is null.\n");
+
+ /* package is not installed. Go for installation. */
+ if (info) {
+ free(info);
+ info = NULL;
+ }
+ _ri_broadcast_status_notification(info->package_name, "start", "install");
+
+ err = _rpm_install_pkg(pkgfilepath, installoptions);
+ if (err != 0) {
+ _d_msg(DEBUG_ERR,
+ "install complete with error(%d)\n", err);
+ return err;
+ } else {
+ _ri_set_backend_state_info(REQUEST_COMPLETED);
+ return RPM_INSTALLER_SUCCESS;
+ }
+ } else if (strcmp(info->version, tmpinfo->version) > 0) {
+ /*upgrade */
+
+ _d_msg(DEBUG_INFO, "[upgrade] %s, %s\n", info->version, tmpinfo->version);
+
+ _ri_broadcast_status_notification(info->package_name, "start", "update");
+
+ err = _rpm_upgrade_pkg(pkgfilepath, "--force");
+ if (err != 0) {
+ _d_msg(DEBUG_ERR,
+ "upgrade complete with error(%d)\n", err);
+ if (info) {
+ free(info);
+ info = NULL;
+ }
+ if (tmpinfo) {
+ free(tmpinfo);
+ tmpinfo = NULL;
+ }
+ return err;
+ } else {
+ _ri_set_backend_state_info(REQUEST_COMPLETED);
+ if (info) {
+ free(info);
+ info = NULL;
+ }
+ if (tmpinfo) {
+ free(tmpinfo);
+ tmpinfo = NULL;
+ }
+ return RPM_INSTALLER_SUCCESS;
+ }
+ } else if (strcmp(info->version, tmpinfo->version) < 0) {
+ /*show popup and confirm from user */
+
+ _d_msg(DEBUG_INFO, "[down grade] %s, %s\n", info->version, tmpinfo->version);
+
+ switch (do_upgrade) {
+ case -1:
+ _ri_set_backend_state_info(REQUEST_PENDING);
+ if (info) {
+ free(info);
+ info = NULL;
+ }
+ if (tmpinfo) {
+ free(tmpinfo);
+ tmpinfo = NULL;
+ }
+ return RPM_INSTALLER_ERR_NEED_USER_CONFIRMATION;
+ case 0:
+ /*return */
+ if (info) {
+ free(info);
+ info = NULL;
+ }
+ if (tmpinfo) {
+ free(tmpinfo);
+ tmpinfo = NULL;
+ }
+ _ri_set_backend_state_info(REQUEST_COMPLETED);
+ return RPM_INSTALLER_ERR_PACKAGE_NOT_UPGRADED;
+ case 1:
+ /*continue with downgrade */
+ _ri_set_backend_state_info
+ (GOT_PACKAGE_INFO_SUCCESSFULLY);
+
+ _ri_broadcast_status_notification(info->package_name, "start", "update");
+
+ err = _rpm_upgrade_pkg(pkgfilepath, "--force");
+ if (err != 0) {
+ _d_msg(DEBUG_ERR,
+ "upgrade complete with error(%d)\n",
+ err);
+ if (info) {
+ free(info);
+ info = NULL;
+ }
+ if (tmpinfo) {
+ free(tmpinfo);
+ tmpinfo = NULL;
+ }
+ return err;
+ }
+ _ri_set_backend_state_info(REQUEST_COMPLETED);
+ if (info) {
+ free(info);
+ info = NULL;
+ }
+ if (tmpinfo) {
+ free(tmpinfo);
+ tmpinfo = NULL;
+ }
+ return RPM_INSTALLER_SUCCESS;
+
+ }
+
+ } else {
+ /*same package. Reinstall it. Manifest should be parsed again */
+
+ _d_msg(DEBUG_INFO, "[same pkg] %s, %s\n", info->package_name, info->version);
+
+ _ri_broadcast_status_notification(info->package_name, "start", "update");
+
+ err = _rpm_upgrade_pkg(pkgfilepath, "--force");
+ if (err != 0) {
+ _d_msg(DEBUG_ERR,
+ "upgrade complete with error(%d)\n", err);
+ if (info) {
+ free(info);
+ info = NULL;
+ }
+ if (tmpinfo) {
+ free(tmpinfo);
+ tmpinfo = NULL;
+ }
+ return err;
+ } else {
+ _ri_set_backend_state_info(REQUEST_COMPLETED);
+ if (info) {
+ free(info);
+ info = NULL;
+ }
+ if (tmpinfo) {
+ free(tmpinfo);
+ tmpinfo = NULL;
+ }
+ return RPM_INSTALLER_SUCCESS;
+ }
+ }
+ if (info) {
+ free(info);
+ info = NULL;
+ }
+ if (tmpinfo) {
+ free(tmpinfo);
+ tmpinfo = NULL;
+ }
+ return RPM_INSTALLER_SUCCESS;
+
+}
+
+int _rpm_installer_package_install_with_dbpath(char *pkgfilepath)
+{
+ int ret = 0;
+ pkginfo *info = NULL;
+ pkginfo *tmpinfo = NULL;
+
+ /*Check to see if the package is already installed or not
+ If it is installed, compare the versions. If the current version
+ is higher than the installed version, upgrade it automatically
+ else ask for user confirmation before downgrading */
+
+ _d_msg(DEBUG_INFO, "[##]start : _rpm_installer_package_install_with_dbpath\n");
+
+ info = _rpm_installer_get_pkgfile_info(pkgfilepath);
+ if (info == NULL) {
+ _d_msg(DEBUG_ERR, "@Failed to get pkg info.\n");
+ /* failed to get pkg info */
+ return RPM_INSTALLER_ERR_INTERNAL;
+ }
+
+ _ri_set_backend_state_info(GOT_PACKAGE_INFO_SUCCESSFULLY);
+
+ tmpinfo = _rpm_installer_get_pkgname_info(info->package_name);
+ if (tmpinfo == NULL) {
+ /* package is not installed. Go for installation. */
+ _d_msg(DEBUG_INFO, "#package is not installed. Go for installation\n");
+ ret = _rpm_install_pkg_with_dbpath(pkgfilepath, info->package_name);
+
+ } else if (strcmp(info->version, tmpinfo->version) > 0) {
+ /*upgrade */
+ _d_msg(DEBUG_INFO, "#package is installed. Go for upgrade\n");
+ ret = _rpm_upgrade_pkg_with_dbpath(pkgfilepath, info->package_name);
+
+ } else {
+ /*same package. Reinstall it. Manifest should be parsed again */
+ _d_msg(DEBUG_INFO, "#package is same. Go for reinstall(upgrade)\n");
+ ret = _rpm_upgrade_pkg_with_dbpath(pkgfilepath, info->package_name);
+ }
+
+ if (info) {
+ free(info);
+ info = NULL;
+ }
+ if (tmpinfo) {
+ free(tmpinfo);
+ tmpinfo = NULL;
+ }
+
+ if (ret != 0) {
+ _d_msg(DEBUG_ERR, "[@@]end : _rpm_installer_package_install_with_dbpath(%d)\n", ret);
+ } else {
+ _d_msg(DEBUG_INFO, "[##]end : _rpm_installer_package_install_with_dbpath \n");
+ }
+
+ return ret;
+}
+
+int _rpm_installer_package_uninstall_with_dbpath(char *pkgid)
+{
+ return _rpm_uninstall_pkg_with_dbpath(pkgid, 0);
+}
+
+int _rpm_installer_package_uninstall(char *pkgid)
+{
+ int ret = 0;
+
+ _d_msg(DEBUG_INFO, "start : _rpm_installer_package_uninstall\n");
+
+ pkginfo *tmppkginfo = _rpm_installer_get_pkgname_info(pkgid);
+ if (tmppkginfo == NULL) {
+ _d_msg(DEBUG_ERR, "tmppkginfo is NULL.\n");
+ return RPM_INSTALLER_ERR_PACKAGE_NOT_INSTALLED;
+ }
+ if (tmppkginfo) {
+ free(tmppkginfo);
+ tmppkginfo = NULL;
+ }
+#ifndef SEND_PKGPATH
+ if (gpkgname) {
+ free(gpkgname);
+ gpkgname = NULL;
+ }
+
+ gpkgname = strdup(pkgid);
+// _ri_broadcast_status_notification(pkgid, "command", "Uninstall");
+#endif
+ _ri_set_backend_state_info(GOT_PACKAGE_INFO_SUCCESSFULLY);
+ ret = _rpm_uninstall_pkg(pkgid);
+
+ _ri_set_backend_state_info(REQUEST_COMPLETED);
+
+ _d_msg(DEBUG_INFO, "end : _rpm_installer_package_uninstall(%d)\n", ret);
+
+ return ret;
+}
+
+int _rpm_installer_clear_private_data(char *pkgid)
+{
+ if (pkgid == NULL)
+ return RPM_INSTALLER_ERR_WRONG_PARAM;
+ char dir_path[BUF_SIZE] = { '\0' };
+ int ret = -1;
+ snprintf(dir_path, 255, "/opt/usr/apps/%s/data/", pkgid);
+ ret = __ri_recursive_delete_dir(dir_path);
+ return ret;
+}
--- /dev/null
+/*
+ * rpm-installer
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
+ * Jaeho Lee <jaeho81.lee@samsung.com>, Shobhit Srivastava <shobhit.s@samsung.com>
+ *
+ * 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 <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <getopt.h>
+#include <fcntl.h>
+#include <dirent.h>
+#include <unistd.h>
+#include <ctype.h>
+#include <rpmlib.h>
+#include <header.h>
+#include <rpmts.h>
+#include <rpmdb.h>
+#include "rpm-installer.h"
+#include "rpm-frontend.h"
+#include <pkgmgr_installer.h>
+
+#define RPM "/usr/etc/package-manager/backend/rpm"
+#define BUFF_SIZE 256
+
+char *gpkgname = NULL;
+extern char scrolllabel[256];
+extern int move_type;
+enum optionsflags {
+ INVALID_OPTIONS = 0,
+ FORCE_OVERWITE = 1,
+ IGNORE_DEPENDS = 2,
+};
+
+struct ri_backend_data_t {
+ int req_cmd;
+ char *cmd_string;
+ char *pkgid;
+ int force_overwrite;
+};
+
+typedef struct ri_backend_data_t ri_backend_data;
+static int __ri_native_recovery(int lastbackstate);
+static int __ri_uninstall_package(char *pkgid);
+static int __ri_clear_private_data(char *pkgid);
+static int __ri_move_package(char *pkgid, int move_type);
+static inline int __ri_read_proc(const char *path, char *buf, int size);
+static inline int __ri_find_pid_by_cmdline(const char *dname,
+ const char *cmdline,
+ const char *priv);
+static bool __ri_is_another_instance_running(const char *exepath);
+
+static int __ri_uninstall_package(char *pkgid)
+{
+
+ if (pkgid == NULL)
+ return RPM_INSTALLER_ERR_WRONG_PARAM;
+ int ret = 0;
+ ret = _rpm_installer_package_uninstall(pkgid);
+ if (ret == RPM_INSTALLER_ERR_PACKAGE_NOT_INSTALLED) {
+ _d_msg(DEBUG_ERR, "[__ri_uninstall_package]%s "
+ "not installed\n", pkgid);
+ } else if (ret != 0) {
+ _d_msg(DEBUG_ERR,
+ "[__ri_uninstall_package]%s uninstall failed(%d)\n",
+ pkgid, ret);
+ } else {
+ _d_msg(DEBUG_ERR,
+ "[__ri_uninstall_package]%s successfully uninstalled\n",
+ pkgid);
+ }
+ return ret;
+}
+
+static int __ri_clear_private_data(char *pkgid)
+{
+ if (pkgid == NULL)
+ return RPM_INSTALLER_ERR_WRONG_PARAM;
+ int ret = 0;
+ ret = _rpm_installer_clear_private_data(pkgid);
+ if (ret == RPM_INSTALLER_SUCCESS) {
+ _d_msg(DEBUG_ERR,
+ "[__clear_private_data]%s clear data successful\n",
+ pkgid);
+ } else {
+ _d_msg(DEBUG_ERR,
+ "[__clear_private_data]%s clear data failed(%d)\n",
+ pkgid, ret);
+ }
+ return ret;
+}
+
+static int __ri_move_package(char *pkgid, int move_type)
+{
+ if (pkgid == NULL)
+ return RPM_INSTALLER_ERR_WRONG_PARAM;
+ int ret = 0;
+ ret = _rpm_move_pkg(pkgid, move_type);
+ if (ret == RPM_INSTALLER_SUCCESS) {
+ _d_msg(DEBUG_ERR,
+ "[__ri_move_package]%s move successful\n",
+ pkgid);
+ } else {
+ _d_msg(DEBUG_ERR,
+ "[__ri_move_package]%s move failed(%d)\n",
+ pkgid, ret);
+ }
+ return ret;
+}
+
+static inline int __ri_read_proc(const char *path, char *buf, int size)
+{
+ int fd;
+ int ret;
+
+ if (buf == NULL || path == NULL)
+ return -1;
+
+ fd = open(path, O_RDONLY);
+ if (fd < 0)
+ return -1;
+
+ ret = read(fd, buf, size - 1);
+ if (ret <= 0) {
+ close(fd);
+ return -1;
+ } else
+ buf[ret] = 0;
+
+ close(fd);
+
+ return ret;
+}
+
+static inline int __ri_find_pid_by_cmdline(const char *dname,
+ const char *cmdline,
+ const char *priv)
+{
+ int pid = 0;
+ if (strncmp(cmdline, priv, strlen(RPM)) == 0) {
+ pid = atoi(dname);
+ if (pid != getpgid(pid))
+ pid = 0;
+ if (pid == getpid())
+ pid = 0;
+ }
+
+ return pid;
+}
+
+static bool __ri_is_another_instance_running(const char *exepath)
+{
+ DIR *dp;
+ struct dirent *dentry;
+ int pid;
+ int ret;
+ char buf[256] = { 0, };
+ char buf1[256] = { 0, };
+ dp = opendir("/proc");
+ if (dp == NULL) {
+ return 0;
+ }
+ while ((dentry = readdir(dp)) != NULL) {
+ if (!isdigit(dentry->d_name[0]))
+ continue;
+ snprintf(buf, sizeof(buf), "/proc/%s/cmdline", dentry->d_name);
+ ret = __ri_read_proc(buf, buf1, sizeof(buf));
+ if (ret <= 0)
+ continue;
+ pid = __ri_find_pid_by_cmdline(dentry->d_name, buf1, exepath);
+ if (pid > 0) {
+ closedir(dp);
+ return 1;
+ }
+ }
+
+ closedir(dp);
+ return 0;
+
+}
+
+static int __ri_native_recovery(int lastbackstate)
+{
+ char *pn = NULL;
+ int lreq;
+ int opt;
+ int err = 0;
+
+ _d_msg(DEBUG_INFO, "Rpm Installer Recovery Entry \n");
+
+ /* which package it was installing and what was state at that time */
+ _ri_get_last_input_info(&pn, &lreq, &opt);
+
+ switch (lastbackstate) {
+ case REQUEST_ACCEPTED:
+ case GOT_PACKAGE_INFO_SUCCESSFULLY:
+ /*
+ * restart the last operation
+ */
+ _d_msg(DEBUG_INFO,
+ "Rpm Installer Recovery started. state=%d \n", lastbackstate);
+ switch (lreq) {
+ case INSTALL_CMD:
+ err =
+ _rpm_installer_package_install(pn, true, "--force");
+ if (err)
+ goto RECOVERYERROR;
+ break;
+
+ case DELETE_CMD:
+ err = _rpm_installer_package_uninstall(pn);
+ if (err)
+ goto RECOVERYERROR;
+ break;
+
+ case CLEARDATA_CMD:
+ case MOVE_CMD:
+ case RECOVER_CMD:
+ /*TODO*/
+ _d_msg(DEBUG_INFO,
+ "Recovery of command(%d) is to be implemented\n", lreq);
+ return 0;
+ }
+ _d_msg(DEBUG_INFO,
+ " Rpm Installer Recovery Ended \n");
+ break;
+ case REQUEST_COMPLETED:
+ _d_msg(DEBUG_INFO,
+ " Rpm Installer Recovery. Nothing To Be Done\n");
+ _ri_set_backend_state_info(REQUEST_COMPLETED);
+ break;
+
+ case REQUEST_PENDING:
+ _d_msg(DEBUG_INFO,
+ "Rpm Installer Recovery started. state=%d\n", lastbackstate);
+ /*Only package downgradation can be the case*/
+ err = _rpm_installer_package_install(pn, true, "--force");
+ if (err != RPM_INSTALLER_SUCCESS &&
+ err != RPM_INSTALLER_ERR_NEED_USER_CONFIRMATION) {
+ goto RECOVERYERROR;
+ }
+ _d_msg(DEBUG_INFO,
+ " Rpm Installer Recovery ended \n");
+ _ri_set_backend_state_info(REQUEST_COMPLETED);
+ break;
+
+ default:
+ /*
+ * Unknown state
+ * No need to recover
+ */
+ _d_msg(DEBUG_INFO,
+ " Rpm Installer Recovery Default state \n");
+ break;
+
+ }
+ return 0;
+
+ RECOVERYERROR:
+ _d_msg(DEBUG_ERR, "Error in Recovery error number = (%d)\n",
+ err);
+ return err;
+
+}
+
+static int __ri_check_root_path(const char *pkgid)
+{
+ char dirpath[BUFF_SIZE] = {'\0'};
+ struct stat stFileInfo;
+
+ snprintf(dirpath, BUFF_SIZE, "/usr/apps/%s", pkgid);
+
+ (void)stat(dirpath, &stFileInfo);
+
+ if (S_ISDIR(stFileInfo.st_mode)) {
+ return 0; //it menas "/usr/apps/pkgid"
+ }
+ return 1; //it menas "/opt/usr/apps/pkgid"
+}
+
+static int __ri_process_smack(char *keyid, char *pkgid)
+{
+ int ret = 0;
+
+ /*apply smack for ug*/
+ if(strcmp(keyid,"ug-smack")==0) {
+ _d_msg(DEBUG_INFO, "only apply smack for ug\n");
+ char *perm[] = {"http://tizen.org/privilege/appsetting", NULL};
+ _ri_apply_smack(pkgid,__ri_check_root_path(pkgid));
+ _ri_privilege_enable_permissions(pkgid, 1, perm, 1);
+ /*apply smack for rpm package*/
+ } else if (strcmp(keyid,"rpm-smack")==0) {
+ _d_msg(DEBUG_INFO, "apply smack for rpm\n");
+ _ri_apply_smack(pkgid,__ri_check_root_path(pkgid));
+ /*register xml to db, call pkgmgr parser*/
+ } else if (strcmp(keyid,"core-xml")==0) {
+ _d_msg(DEBUG_INFO, "install corexml\n");
+ ret = _rpm_installer_corexml_install(pkgid);
+ if (ret != 0) {
+ _d_msg(DEBUG_ERR, "corexml_install failed with err(%d)\n", ret);
+ } else {
+ _d_msg(DEBUG_INFO, "corexml_install success\n");
+ }
+ /*apply privilege for rpm package*/
+ } else if (strcmp(keyid,"rpm-perm")==0) {
+ _d_msg(DEBUG_INFO, "apply permmissions for rpm\n");
+ ret = _ri_apply_perm(pkgid);
+ if (ret != 0) {
+ _d_msg(DEBUG_ERR, "apply perm failed with err(%d)\n", ret);
+ } else {
+ _d_msg(DEBUG_INFO, "apply perm success\n");
+ }
+ /*check csc xml*/
+ } else if (strcmp(keyid,"csc-xml")==0) {
+ _d_msg(DEBUG_INFO, "csc xml for rpm\n");
+ ret = _rpm_process_cscxml(pkgid);
+ if (ret != 0) {
+ _d_msg(DEBUG_ERR, "install csc xml failed with err(%d)\n", ret);
+ } else {
+ _d_msg(DEBUG_INFO, "install csc xml success\n");
+ }
+ /*check fota*/
+ } else if (strcmp(keyid,"rpm-fota")==0) {
+ _d_msg(DEBUG_INFO, "fota process for rpm\n");
+ ret = _rpm_process_fota(pkgid);
+ if (ret != 0) {
+ _d_msg(DEBUG_ERR, "fota process failed with err(%d)\n", ret);
+ } else {
+ _d_msg(DEBUG_INFO, "fota process success\n");
+ }
+ /*check fota*/
+ } else if (strcmp(keyid,"rpm-rw-fota")==0) {
+ _d_msg(DEBUG_INFO, "rw fota process for rpm\n");
+ ret = _rpm_process_fota_for_rw(pkgid);
+ if (ret != 0) {
+ _d_msg(DEBUG_ERR, "rw fota process failed with err(%d)\n", ret);
+ } else {
+ _d_msg(DEBUG_INFO, "rw fota process success\n");
+ }
+ } else {
+ _d_msg(DEBUG_ERR, "smack cmd error\n");
+ ret = -1;
+ }
+
+ return ret;
+}
+
+int _rpm_backend_interface(char *keyid, char *pkgid, char *reqcommand)
+{
+ int ret = -1;
+ ri_backend_data data = { 0 };
+ int backendstate;
+ rpmRC rc;
+ if (reqcommand == NULL) {
+ _d_msg(DEBUG_ERR, "reqcommand is NULL\n");
+ return RPM_INSTALLER_ERR_WRONG_PARAM;
+ }
+ if (keyid == NULL || pkgid == NULL) {
+ if (strncmp(reqcommand, "recover", strlen("recover"))) {
+ _d_msg(DEBUG_ERR, " Either keyid/pkgid is NULL\n");
+ return RPM_INSTALLER_ERR_WRONG_PARAM;
+ }
+ }
+
+ if (strncmp(reqcommand, "install", strlen("install")) == 0) {
+ data.req_cmd = INSTALL_CMD;
+ data.cmd_string = strdup("install");
+ if (data.cmd_string == NULL) {
+ _d_msg(DEBUG_ERR,
+ "strdup failed due to insufficient memory\n");
+ return RPM_INSTALLER_ERR_NOT_ENOUGH_MEMORY;
+ }
+ } else if (strncmp(reqcommand, "remove", strlen("remove")) == 0) {
+ data.req_cmd = DELETE_CMD;
+ data.cmd_string = strdup("uninstall");
+ if (data.cmd_string == NULL) {
+ _d_msg(DEBUG_ERR,
+ "strdup failed due to insufficient memory\n");
+ return RPM_INSTALLER_ERR_NOT_ENOUGH_MEMORY;
+ }
+ } else if (strncmp(reqcommand, "recover", strlen("recover")) == 0) {
+ data.req_cmd = RECOVER_CMD;
+ data.cmd_string = strdup("recover");
+ if (data.cmd_string == NULL) {
+ _d_msg(DEBUG_ERR,
+ "strdup failed due to insufficient memory\n");
+ return RPM_INSTALLER_ERR_NOT_ENOUGH_MEMORY;
+ }
+ } else if (strncmp(reqcommand, "cleardata", strlen("cleardata")) == 0) {
+ data.req_cmd = CLEARDATA_CMD;
+ data.cmd_string = strdup("cleardata");
+ if (data.cmd_string == NULL) {
+ _d_msg(DEBUG_ERR,
+ "strdup failed due to insufficient memory\n");
+ return RPM_INSTALLER_ERR_NOT_ENOUGH_MEMORY;
+ }
+ } else if (strncmp(reqcommand, "move", strlen("move")) == 0) {
+ data.req_cmd = MOVE_CMD;
+ data.cmd_string = strdup("move");
+ if (data.cmd_string == NULL) {
+ _d_msg(DEBUG_ERR,
+ "strdup failed due to insufficient memory\n");
+ return RPM_INSTALLER_ERR_NOT_ENOUGH_MEMORY;
+ }
+ } else if (strncmp(reqcommand, "smack", strlen("smack")) == 0) {
+ return __ri_process_smack(keyid, pkgid);
+ } else if (strncmp(reqcommand, "eflwgt-install", strlen("eflwgt-install")) == 0) {
+ return _rpm_installer_package_install_with_dbpath(pkgid);
+ } else if (strncmp(reqcommand, "eflwgt-remove", strlen("eflwgt-remove")) == 0) {
+ return _rpm_installer_package_uninstall_with_dbpath(pkgid);
+ } else if (strncmp(reqcommand, "rpm-enable", strlen("rpm-enable")) == 0) {
+ if (strstr(pkgid, ":") == NULL)
+ ret = _rpm_process_enable(pkgid);
+ else
+ ret = _rpm_process_enabled_list(pkgid);
+ return ret;
+ } else if (strncmp(reqcommand, "rpm-disable", strlen("rpm-disable")) == 0) {
+ if (strstr(pkgid, ":") == NULL)
+ ret = _rpm_process_disable(pkgid);
+ else
+ ret = _rpm_process_disabled_list(pkgid);
+ return ret;
+ } else {
+ _d_msg(DEBUG_INFO, "wrong input parameter\n");
+ _d_msg(DEBUG_RESULT, "%d\n", RPM_INSTALLER_ERR_WRONG_PARAM);
+ return RPM_INSTALLER_ERR_WRONG_PARAM;
+ }
+
+ data.pkgid = pkgid;
+ backendstate = _ri_get_backend_state();
+
+ rc = rpmReadConfigFiles(NULL, NULL);
+ if (rc == RPMRC_OK) {
+ _d_msg(DEBUG_INFO, "Successfully read rpm configuration\n");
+ } else {
+ _d_msg(DEBUG_ERR, "Unable to read RPM configuration.\n");
+ if (data.cmd_string) {
+ free(data.cmd_string);
+ data.cmd_string = NULL;
+ }
+ return RPM_INSTALLER_ERR_INTERNAL;
+ }
+
+ if (RECOVER_CMD == data.req_cmd) {
+ if (0 == backendstate) {
+ int lastbackstate;
+
+ /* check the current state of backend */
+ lastbackstate = _ri_get_backend_state_info();
+
+ if (REQUEST_COMPLETED == lastbackstate) {
+ _d_msg(DEBUG_INFO,
+ " Rpm Installer recovery is in REQUEST_COMPLETED \n");
+ snprintf(scrolllabel, sizeof(scrolllabel),
+ "No Recovery Needed");
+ } else
+ ret = __ri_native_recovery(lastbackstate);
+ if (ret == 0)
+ snprintf(scrolllabel, sizeof(scrolllabel),
+ "Recovery Success");
+ else
+ snprintf(scrolllabel, sizeof(scrolllabel),
+ "Recovery Failed");
+
+ /* set the backend state as completed */
+ _ri_set_backend_state(1);
+ } else {
+ /* nothing to recover */
+ _d_msg(DEBUG_INFO,
+ " Rpm Installer recovery Nothing to be done\n");
+ ret = 0;
+ snprintf(scrolllabel, sizeof(scrolllabel),
+ "No Recovery Needed");
+ }
+ _d_msg(DEBUG_RESULT, "%d\n", ret);
+ if (data.cmd_string) {
+ free(data.cmd_string);
+ data.cmd_string = NULL;
+ }
+ return ret;
+
+ }
+ if (backendstate == 0) {
+
+ /* Non Recovery case
+ *
+ * Another Instance may be running
+ * or something went wrong in last execution
+ * Check for it
+ */
+ if (__ri_is_another_instance_running(RPM)) {
+ if (data.pkgid) {
+ _ri_broadcast_status_notification
+ (data.pkgid, "error",
+ "Another Instance Running");
+ _ri_stat_cb(data.pkgid, "error",
+ "Another Instance Running");
+ _ri_broadcast_status_notification
+ (data.pkgid, "end", "fail");
+ _ri_stat_cb(data.pkgid, "end",
+ "fail");
+ } else {
+ _ri_broadcast_status_notification
+ ("unknown", "error",
+ "Another Instance Running");
+ _ri_stat_cb("unknown", "error",
+ "Another Instance Running");
+ _ri_broadcast_status_notification
+ ("unknown", "end", "fail");
+ _ri_stat_cb("unknown", "end", "fail");
+ }
+ _d_msg(DEBUG_INFO,
+ "Request Failed as "
+ "Another Instance is running \n");
+ ret = RPM_INSTALLER_ERR_RESOURCE_BUSY;
+ if (data.cmd_string) {
+ free(data.cmd_string);
+ data.cmd_string = NULL;
+ }
+ return ret;
+ } else {
+ int lastbackstate;
+
+ /* check the current state of backend */
+ lastbackstate = _ri_get_backend_state_info();
+
+ /* Publish Notification that backend has started */
+// _ri_broadcast_status_notification(data.pkgid, "start", data.cmd_string);
+// _ri_broadcast_status_notification(data.pkgid, "command", data.cmd_string);
+
+ if (REQUEST_COMPLETED == lastbackstate) {
+ _d_msg(DEBUG_INFO,
+ " Rpm Installer recovery"
+ " is in REQUEST_COMPLETED \n");
+ ret = 0;
+ } else
+ ret = __ri_native_recovery(lastbackstate);
+ if (ret != 0) {
+ _d_msg(DEBUG_INFO,
+ "recovery of last request failed\n");
+ } else {
+ _d_msg(DEBUG_INFO,
+ "recovery of last request success\n");
+ }
+
+ /* set the backend state as completed */
+ _ri_set_backend_state(1);
+ }
+ }
+
+ /* set the backend state as started for the current request*/
+ _ri_set_backend_state(0);
+
+#ifdef SEND_PKGPATH
+ gpkgname = strdup(data.pkgid);
+
+ /* Publish Notification that backend has started */
+ if (data.pkgid)
+ _ri_broadcast_status_notification(data.pkgid, "start",
+ data.cmd_string);
+ else
+ _ri_broadcast_status_notification("unknown", "start",
+ data.cmd_string);
+#endif
+
+ _ri_set_backend_state_info(REQUEST_ACCEPTED);
+
+ /* Set the input request info */
+ _ri_save_last_input_info(data.pkgid, data.req_cmd,
+ data.force_overwrite);
+
+ switch (data.req_cmd) {
+ case INSTALL_CMD:
+ {
+ _d_msg(DEBUG_INFO, "[%s] --install %s\n",
+ "backend", data.pkgid);
+#ifdef SEND_PKGPATH
+ _ri_broadcast_status_notification(data.pkgid,
+ "command", "Install");
+#endif
+ if (data.force_overwrite == FORCE_OVERWITE) {
+ _d_msg(DEBUG_INFO,
+ "[%s] --install %s --force-overwrite\n",
+ "backend", data.pkgid);
+ ret =
+ _rpm_installer_package_install
+ (data.pkgid, true, "--force");
+ } else {
+ if(data.pkgid == NULL) {
+ _d_msg(DEBUG_ERR, "pkgid is null");
+ break;
+ }
+ _d_msg(DEBUG_INFO, "[%s] --install %s\n",
+ "backend", data.pkgid);
+ ret =
+ _rpm_installer_package_install
+ (data.pkgid, false, NULL);
+ }
+ if (ret == RPM_INSTALLER_ERR_NEED_USER_CONFIRMATION) {
+ break;
+ } else if (ret == RPM_INSTALLER_SUCCESS) {
+ _d_msg(DEBUG_INFO, "install success\n");
+ _ri_broadcast_status_notification(data.pkgid,
+ "end", "ok");
+ _ri_stat_cb(data.pkgid, "end", "ok");
+ } else {
+
+ char *errstr = NULL;
+ _ri_error_no_to_string(ret, &errstr);
+ _ri_broadcast_status_notification(data.pkgid,
+ "error",
+ errstr);
+ _ri_stat_cb(data.pkgid, "error", errstr);
+ _ri_broadcast_status_notification(data.pkgid,
+ "end",
+ "fail");
+ sleep(2);
+ _ri_stat_cb(data.pkgid, "end", "fail");
+ _d_msg(DEBUG_ERR,
+ "install failed with err(%d) (%s)\n",
+ ret, errstr);
+ }
+ }
+ break;
+ case DELETE_CMD:
+ {
+ _d_msg(DEBUG_INFO, "[%s] uninstall %s\n",
+ "backend", data.pkgid);
+#ifdef SEND_PKGPATH
+ _ri_broadcast_status_notification(data.pkgid,
+ "command", "Remove");
+#endif
+ ret = __ri_uninstall_package(data.pkgid);
+ if (ret != 0) {
+ char *errstr = NULL;
+ _ri_error_no_to_string(ret, &errstr);
+ _ri_broadcast_status_notification(data.pkgid,
+ "error",
+ errstr);
+ _ri_stat_cb(data.pkgid, "error", errstr);
+ sleep(2);
+ _ri_broadcast_status_notification(data.pkgid,
+ "end",
+ "fail");
+ _ri_stat_cb(data.pkgid, "end", "fail");
+ _d_msg(DEBUG_ERR,
+ "remove failed with err(%d) (%s)\n",
+ ret, errstr);
+ } else {
+ _d_msg(DEBUG_INFO, "remove success\n");
+ _ri_broadcast_status_notification(data.pkgid,
+ "end", "ok");
+ _ri_stat_cb(data.pkgid, "end", "ok");
+ }
+ }
+ break;
+ case CLEARDATA_CMD:
+ {
+ _d_msg(DEBUG_INFO, "[%s] clear data %s\n",
+ "backend", data.pkgid);
+#ifdef SEND_PKGPATH
+ _ri_broadcast_status_notification(data.pkgid,
+ "command", "clear");
+#endif
+ ret = __ri_clear_private_data(data.pkgid);
+ if (ret != 0) {
+ char *errstr = NULL;
+ _ri_error_no_to_string(ret, &errstr);
+ _ri_broadcast_status_notification(data.pkgid,
+ "error",
+ errstr);
+ _ri_stat_cb(data.pkgid, "error", errstr);
+ _ri_broadcast_status_notification(data.pkgid,
+ "end",
+ "fail");
+ _ri_stat_cb(data.pkgid, "end", "fail");
+ _d_msg(DEBUG_ERR,
+ "clear data failed with err(%d) (%s)\n",
+ ret, errstr);
+ } else {
+ _d_msg(DEBUG_INFO, "clear data success\n");
+ _ri_broadcast_status_notification(data.pkgid,
+ "end", "ok");
+ _ri_stat_cb(data.pkgid, "end", "ok");
+ }
+ break;
+ }
+ case MOVE_CMD:
+ {
+ _d_msg(DEBUG_INFO, "[%s] move %s\n",
+ "backend", data.pkgid);
+#ifdef SEND_PKGPATH
+ _ri_broadcast_status_notification(data.pkgid,
+ "command", "move");
+#endif
+ ret = __ri_move_package(data.pkgid, move_type);
+ if (ret != 0) {
+ char *errstr = NULL;
+ _ri_error_no_to_string(ret, &errstr);
+ _ri_broadcast_status_notification(data.pkgid,
+ "error",
+ errstr);
+ _ri_stat_cb(data.pkgid, "error", errstr);
+ _ri_broadcast_status_notification(data.pkgid,
+ "end",
+ "fail");
+ _ri_stat_cb(data.pkgid, "end", "fail");
+ _d_msg(DEBUG_ERR,
+ "move failed with err(%d) (%s)\n",
+ ret, errstr);
+ } else {
+ _d_msg(DEBUG_INFO, "move success\n");
+ _ri_broadcast_status_notification(data.pkgid,
+ "end", "ok");
+ _ri_stat_cb(data.pkgid, "end", "ok");
+ }
+ break;
+ }
+
+ default:
+ {
+ _ri_broadcast_status_notification("unknown", "command",
+ "unknown");
+ _ri_broadcast_status_notification("unknown", "error",
+ "not supported");
+ _ri_stat_cb("unknown", "error", "not supported");
+ _ri_broadcast_status_notification("unknown",
+ "end", "fail");
+ _ri_stat_cb("unknown", "end", "fail");
+ _d_msg(DEBUG_ERR, "unknown command \n");
+ ret = RPM_INSTALLER_ERR_WRONG_PARAM;
+ }
+ }
+
+ if (gpkgname) {
+ free(gpkgname);
+ gpkgname = NULL;
+ }
+
+ if (data.cmd_string) {
+ free(data.cmd_string);
+ data.cmd_string = NULL;
+ }
+
+ if (_ri_get_backend_state_info() != REQUEST_PENDING) {
+ _ri_set_backend_state_info(REQUEST_COMPLETED);
+ /* set the backend state as completed */
+ _ri_set_backend_state(1);
+ _d_msg(DEBUG_INFO, "%d\n", ret);
+ _d_msg_deinit();
+ }
+ return ret;
+}
--- /dev/null
+/*
+ * rpm-installer
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ *
+ * 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.
+ *
+ */
+
+#ifndef __RPM_INSTALLER_TYPE_H_
+#define __RPM_INSTALLER_TYPE_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+#define MAX_BUF_SIZE 4096
+#define BUF_SIZE 1024
+#define TEMP_DIR "/opt/usr/rpminstaller"
+#define CPIO_SCRIPT "/usr/bin/cpio_rpm_package.sh"
+#define CPIO_SCRIPT_UPDATE_XML "/usr/bin/cpio_rpm_package_update_xml.sh"
+#define MANIFEST_RW_DIRECTORY "/opt/share/packages"
+#define MANIFEST_RO_DIRECTORY "/usr/share/packages"
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+#endif /* __RPM_INSTALLER_TYPE_H_ */
--- /dev/null
+/*
+ * rpm-installer
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
+ * Jaeho Lee <jaeho81.lee@samsung.com>, Shobhit Srivastava <shobhit.s@samsung.com>
+ *
+ * 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.
+ *
+ */
+
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE
+#endif
+#define __USE_GNU
+#include <unistd.h>
+#include <stdio.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <privilege-control.h>
+
+#include "rpm-installer.h"
+
+
+
+static int __ri_privilege_perm_begin(void)
+{
+ int ret = 0;
+
+ ret = perm_begin();
+ _d_msg(DEBUG_INFO, "[smack] perm_begin, result = [%d]",ret);
+
+ return ret;
+}
+
+static int __ri_privilege_perm_end(void)
+{
+ int ret = 0;
+
+ ret = perm_end();
+ _d_msg(DEBUG_INFO, "[smack] perm_end, result = [%d]",ret);
+
+ return ret;
+}
+
+int _ri_privilege_register_package(const char *pkgid)
+{
+ int ret = 0;
+
+ ret = perm_app_install(pkgid);
+ _d_msg(DEBUG_INFO, "[smack] app_install(%s), result = [%d]", pkgid, ret);
+
+ return ret;
+}
+
+int _ri_privilege_unregister_package(const char *pkgid)
+{
+ int ret = 0;
+
+ ret = perm_app_uninstall(pkgid);
+ _d_msg(DEBUG_INFO, "[smack] app_uninstall(%s), result = [%d]", pkgid, ret);
+
+ return ret;
+}
+
+int _ri_privilege_revoke_permissions(const char *pkgid)
+{
+ int ret = 0;
+
+ ret = perm_app_revoke_permissions(pkgid);
+ _d_msg(DEBUG_INFO, "[smack] app_revoke_permissions(%s), result = [%d]", pkgid, ret);
+
+ return ret;
+}
+
+int _ri_privilege_enable_permissions(const char *pkgid, int apptype,
+ const char **perms, int persistent)
+{
+ int ret = 0;
+
+ __ri_privilege_perm_begin();
+
+ ret = perm_app_enable_permissions(pkgid, apptype, perms, persistent);
+ _d_msg(DEBUG_INFO, "[smack] app_enable_permissions(%s, %d), result = [%d]", pkgid, apptype, ret);
+
+ __ri_privilege_perm_end();
+
+ return ret;
+}
+
+int _ri_privilege_setup_path(const char *pkgid, const char *dirpath,
+ int apppathtype, const char *groupid)
+{
+ int ret = 0;
+
+ if (groupid == NULL) {
+ ret = perm_app_setup_path(pkgid, dirpath, apppathtype);
+ _d_msg(DEBUG_INFO, "[smack] app_setup_path(%s), result = [%d]", dirpath,ret);
+ } else {
+ ret = perm_app_setup_path(pkgid, dirpath, apppathtype, groupid);
+ _d_msg(DEBUG_INFO, "[smack] app_setup_path(%s), result = [%d]", dirpath, ret);
+ }
+
+ return ret;
+}
+
+int _ri_privilege_add_friend(const char *pkgid1, const char *pkgid2)
+{
+ int ret = 0;
+
+ ret = perm_app_add_friend(pkgid1, pkgid2);
+ _d_msg(DEBUG_INFO, "[smack] app_add_friend(%s, %s), result = [%d]", pkgid1, pkgid2, ret);
+
+ return ret;
+}
+
+int _ri_privilege_change_smack_label(const char *path, const char *label,
+ int label_type)
+{
+ if (path == NULL || label == NULL)
+ return -1;
+ int ret = 0;
+
+ ret = smack_lsetlabel(path, label, label_type);
+ _d_msg(DEBUG_INFO, "[smack] smack_lsetlabel(%s, %s, %d), result = [%d]", path, label, label_type, ret);
+
+ return ret;
+}
--- /dev/null
+/*
+ * rpm-installer
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
+ * Jaeho Lee <jaeho81.lee@samsung.com>, Shobhit Srivastava <shobhit.s@samsung.com>
+ *
+ * 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 <pkgmgr_parser.h>
+#include "rpm-installer-util.h"
+#include "rpm-installer-signature.h"
+
+#define ASCII(s) (const char *)s
+#define XMLCHAR(s) (const xmlChar *)s
+
+static int _ri_next_child_element(xmlTextReaderPtr reader, int depth)
+{
+ int ret = xmlTextReaderRead(reader);
+ int cur = xmlTextReaderDepth(reader);
+ while (ret == 1) {
+
+ switch (xmlTextReaderNodeType(reader)) {
+ case XML_READER_TYPE_ELEMENT:
+ if (cur == depth + 1)
+ return 1;
+ break;
+ case XML_READER_TYPE_TEXT:
+ if (cur == depth + 1)
+ return 0;
+ break;
+ case XML_READER_TYPE_END_ELEMENT:
+ if (cur == depth)
+ return 0;
+ break;
+ default:
+ if (cur <= depth)
+ return 0;
+ break;
+ }
+ ret = xmlTextReaderRead(reader);
+ cur = xmlTextReaderDepth(reader);
+ }
+ return ret;
+}
+
+static void _ri_free_transform(transform_x *transform)
+{
+ if (transform == NULL)
+ return;
+ if (transform->algorithm) {
+ free((void *)transform->algorithm);
+ transform->algorithm = NULL;
+ }
+ free((void*)transform);
+ transform = NULL;
+}
+
+static void _ri_free_cannonicalizationmethod(cannonicalizationmethod_x *cannonicalizationmethod)
+{
+ if (cannonicalizationmethod == NULL)
+ return;
+ if (cannonicalizationmethod->algorithm) {
+ free((void *)cannonicalizationmethod->algorithm);
+ cannonicalizationmethod->algorithm = NULL;
+ }
+ free((void*)cannonicalizationmethod);
+ cannonicalizationmethod = NULL;
+}
+
+static void _ri_free_signaturemethod(signaturemethod_x *signaturemethod)
+{
+ if (signaturemethod == NULL)
+ return;
+ if (signaturemethod->algorithm) {
+ free((void *)signaturemethod->algorithm);
+ signaturemethod->algorithm = NULL;
+ }
+ free((void*)signaturemethod);
+ signaturemethod = NULL;
+}
+
+static void _ri_free_digestmethod(digestmethod_x *digestmethod)
+{
+ if (digestmethod == NULL)
+ return;
+ if (digestmethod->algorithm) {
+ free((void *)digestmethod->algorithm);
+ digestmethod->algorithm = NULL;
+ }
+ free((void*)digestmethod);
+ digestmethod = NULL;
+}
+
+static void _ri_free_digestvalue(digestvalue_x *digestvalue)
+{
+ if (digestvalue == NULL)
+ return;
+ if (digestvalue->text) {
+ free((void *)digestvalue->text);
+ digestvalue->text = NULL;
+ }
+ free((void*)digestvalue);
+ digestvalue = NULL;
+}
+
+static void _ri_free_signaturevalue(signaturevalue_x *signaturevalue)
+{
+ if (signaturevalue == NULL)
+ return;
+ if (signaturevalue->text) {
+ free((void *)signaturevalue->text);
+ signaturevalue->text = NULL;
+ }
+ free((void*)signaturevalue);
+ signaturevalue = NULL;
+}
+
+static void _ri_free_x509certificate(x509certificate_x *x509certificate)
+{
+ if (x509certificate == NULL)
+ return;
+ if (x509certificate->text) {
+ free((void *)x509certificate->text);
+ x509certificate->text = NULL;
+ }
+ free((void*)x509certificate);
+ x509certificate = NULL;
+}
+
+static void _ri_free_x509data(x509data_x *x509data)
+{
+ if (x509data == NULL)
+ return;
+ if (x509data->x509certificate) {
+ x509certificate_x *x509certificate = x509data->x509certificate;
+ x509certificate_x *tmp = NULL;
+ while(x509certificate != NULL) {
+ tmp = x509certificate->next;
+ _ri_free_x509certificate(x509certificate);
+ x509certificate = tmp;
+ }
+ }
+ free((void*)x509data);
+ x509data = NULL;
+}
+
+static void _ri_free_keyinfo(keyinfo_x *keyinfo)
+{
+ if (keyinfo == NULL)
+ return;
+ if (keyinfo->x509data) {
+ x509data_x *x509data = keyinfo->x509data;
+ x509data_x *tmp = NULL;
+ while(x509data != NULL) {
+ tmp = x509data->next;
+ _ri_free_x509data(x509data);
+ x509data = tmp;
+ }
+ }
+ free((void*)keyinfo);
+ keyinfo = NULL;
+}
+
+static void _ri_free_transforms(transforms_x *transforms)
+{
+ if (transforms == NULL)
+ return;
+ if (transforms->transform) {
+ transform_x *transform = transforms->transform;
+ transform_x *tmp = NULL;
+ while(transform != NULL) {
+ tmp = transform->next;
+ _ri_free_transform(transform);
+ transform = tmp;
+ }
+ }
+ free((void*)transforms);
+ transforms = NULL;
+}
+
+static void _ri_free_reference(reference_x *reference)
+{
+ if (reference == NULL)
+ return;
+ if (reference->digestmethod) {
+ digestmethod_x *digestmethod = reference->digestmethod;
+ digestmethod_x *tmp = NULL;
+ while(digestmethod != NULL) {
+ tmp = digestmethod->next;
+ _ri_free_digestmethod(digestmethod);
+ digestmethod = tmp;
+ }
+ }
+ if (reference->digestvalue) {
+ digestvalue_x *digestvalue = reference->digestvalue;
+ digestvalue_x *tmp = NULL;
+ while(digestvalue != NULL) {
+ tmp = digestvalue->next;
+ _ri_free_digestvalue(digestvalue);
+ digestvalue = tmp;
+ }
+ }
+ if (reference->transforms) {
+ transforms_x *transforms = reference->transforms;
+ transforms_x *tmp = NULL;
+ while(transforms != NULL) {
+ tmp = transforms->next;
+ _ri_free_transforms(transforms);
+ transforms = tmp;
+ }
+ }
+ free((void*)reference);
+ reference = NULL;
+}
+
+static void _ri_free_signedinfo(signedinfo_x *signedinfo)
+{
+ if (signedinfo == NULL)
+ return;
+ if (signedinfo->cannonicalizationmethod) {
+ cannonicalizationmethod_x *cannonicalizationmethod = signedinfo->cannonicalizationmethod;
+ cannonicalizationmethod_x *tmp = NULL;
+ while(cannonicalizationmethod != NULL) {
+ tmp = cannonicalizationmethod->next;
+ _ri_free_cannonicalizationmethod(cannonicalizationmethod);
+ cannonicalizationmethod = tmp;
+ }
+ }
+ if (signedinfo->signaturemethod) {
+ signaturemethod_x *signaturemethod = signedinfo->signaturemethod;
+ signaturemethod_x *tmp = NULL;
+ while(signaturemethod != NULL) {
+ tmp = signaturemethod->next;
+ _ri_free_signaturemethod(signaturemethod);
+ signaturemethod = tmp;
+ }
+ }
+ if (signedinfo->reference) {
+ reference_x *reference = signedinfo->reference;
+ reference_x *tmp = NULL;
+ while(reference != NULL) {
+ tmp = reference->next;
+ _ri_free_reference(reference);
+ reference = tmp;
+ }
+ }
+ free((void*)signedinfo);
+ signedinfo = NULL;
+}
+
+void _ri_free_signature_xml(signature_x *sigx)
+{
+ if (sigx == NULL)
+ return;
+ if (sigx->id) {
+ free((void *)sigx->id);
+ sigx->id = NULL;
+ }
+ if (sigx->xmlns) {
+ free((void *)sigx->xmlns);
+ sigx->xmlns = NULL;
+ }
+ if (sigx->signedinfo) {
+ signedinfo_x *signedinfo = sigx->signedinfo;
+ signedinfo_x *tmp = NULL;
+ while(signedinfo != NULL) {
+ tmp = signedinfo->next;
+ _ri_free_signedinfo(signedinfo);
+ signedinfo = tmp;
+ }
+ }
+ if (sigx->signaturevalue) {
+ signaturevalue_x *signaturevalue = sigx->signaturevalue;
+ signaturevalue_x *tmp = NULL;
+ while(signaturevalue != NULL) {
+ tmp = signaturevalue->next;
+ _ri_free_signaturevalue(signaturevalue);
+ signaturevalue = tmp;
+ }
+ }
+ if (sigx->keyinfo) {
+ keyinfo_x *keyinfo = sigx->keyinfo;
+ keyinfo_x *tmp = NULL;
+ while(keyinfo != NULL) {
+ tmp = keyinfo->next;
+ _ri_free_keyinfo(keyinfo);
+ keyinfo = tmp;
+ }
+ }
+ /*Object will be freed when it will be parsed in future*/
+ free((void*)sigx);
+ sigx = NULL;
+}
+
+static int _ri_process_digestmethod(xmlTextReaderPtr reader, digestmethod_x *digestmethod)
+{
+ if (xmlTextReaderGetAttribute(reader, XMLCHAR("Algorithm")))
+ digestmethod->algorithm = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("Algorithm")));
+ return 0;
+}
+
+static int _ri_process_digestvalue(xmlTextReaderPtr reader, digestvalue_x *digestvalue)
+{
+ xmlTextReaderRead(reader);
+ if (xmlTextReaderValue(reader))
+ digestvalue->text = ASCII(xmlTextReaderValue(reader));
+ return 0;
+}
+
+static int _ri_process_transform(xmlTextReaderPtr reader, transform_x *transform)
+{
+ if (xmlTextReaderGetAttribute(reader, XMLCHAR("Algorithm")))
+ transform->algorithm = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("Algorithm")));
+ return 0;
+}
+
+static int _ri_process_transforms(xmlTextReaderPtr reader, transforms_x *transforms)
+{
+ const xmlChar *node = NULL;
+ int ret = 0;
+ int depth = 0;
+ transform_x *tmp1 = NULL;
+
+ depth = xmlTextReaderDepth(reader);
+ while ((ret = _ri_next_child_element(reader, depth))) {
+ node = xmlTextReaderConstName(reader);
+ if (!node) {
+ _d_msg(DEBUG_ERR, "node is NULL\n");
+ return -1;
+ }
+ if (strcmp(ASCII(node), "Transform") == 0) {
+ transform_x *transform = calloc(1, sizeof(transform_x));
+ if (transform == NULL) {
+ _d_msg(DEBUG_ERR, "Calloc Failed\n");
+ return -1;
+ }
+ LISTADD(transforms->transform, transform);
+ ret = _ri_process_transform(reader, transform);
+ } else {
+ _d_msg(DEBUG_INFO, "Invalid tag %s", ASCII(node));
+ return -1;
+ }
+ if (ret < 0)
+ return ret;
+ }
+ if (transforms->transform) {
+ LISTHEAD(transforms->transform, tmp1);
+ transforms->transform = tmp1;
+ }
+ return ret;
+}
+
+static int _ri_process_cannonicalizationmethod(xmlTextReaderPtr reader, cannonicalizationmethod_x *cannonicalizationmethod)
+{
+ if (xmlTextReaderGetAttribute(reader, XMLCHAR("Algorithm")))
+ cannonicalizationmethod->algorithm = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("Algorithm")));
+ return 0;
+}
+
+static int _ri_process_signaturemethod(xmlTextReaderPtr reader, signaturemethod_x *signaturemethod)
+{
+ if (xmlTextReaderGetAttribute(reader, XMLCHAR("Algorithm")))
+ signaturemethod->algorithm = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("Algorithm")));
+ return 0;
+}
+
+static int _ri_process_reference(xmlTextReaderPtr reader, reference_x *reference)
+{
+ const xmlChar *node = NULL;
+ int ret = 0;
+ int depth = 0;
+ digestmethod_x *tmp1 = NULL;
+ digestvalue_x *tmp2 = NULL;
+ transforms_x *tmp3 = NULL;
+
+ if (xmlTextReaderGetAttribute(reader, XMLCHAR("URI")))
+ reference->uri = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("URI")));
+
+ depth = xmlTextReaderDepth(reader);
+ while ((ret = _ri_next_child_element(reader, depth))) {
+ node = xmlTextReaderConstName(reader);
+ if (!node) {
+ _d_msg(DEBUG_ERR, "node is NULL\n");
+ return -1;
+ }
+ if (strcmp(ASCII(node), "DigestMethod") == 0) {
+ digestmethod_x *digestmethod = calloc(1, sizeof(digestmethod_x));
+ if (digestmethod == NULL) {
+ _d_msg(DEBUG_ERR, "Calloc Failed\n");
+ return -1;
+ }
+ LISTADD(reference->digestmethod, digestmethod);
+ ret = _ri_process_digestmethod(reader, digestmethod);
+ } else if (strcmp(ASCII(node), "DigestValue") == 0) {
+ digestvalue_x *digestvalue = calloc(1, sizeof(digestvalue_x));
+ if (digestvalue == NULL) {
+ _d_msg(DEBUG_ERR, "Calloc Failed\n");
+ return -1;
+ }
+ LISTADD(reference->digestvalue, digestvalue);
+ ret = _ri_process_digestvalue(reader, digestvalue);
+ } else if (strcmp(ASCII(node), "Transforms") == 0) {
+ transforms_x *transforms = calloc(1, sizeof(transforms_x));
+ if (transforms == NULL) {
+ _d_msg(DEBUG_ERR, "Calloc Failed\n");
+ return -1;
+ }
+ LISTADD(reference->transforms, transforms);
+ ret = _ri_process_transforms(reader, transforms);
+ } else {
+ _d_msg(DEBUG_INFO, "Invalid tag %s", ASCII(node));
+ return -1;
+ }
+ if (ret < 0)
+ return ret;
+ }
+ if (reference->digestmethod) {
+ LISTHEAD(reference->digestmethod, tmp1);
+ reference->digestmethod = tmp1;
+ }
+ if (reference->digestvalue) {
+ LISTHEAD(reference->digestvalue, tmp2);
+ reference->digestvalue = tmp2;
+ }
+ if (reference->transforms) {
+ LISTHEAD(reference->transforms, tmp3);
+ reference->transforms = tmp3;
+ }
+ return ret;
+}
+
+static int _ri_process_x509certificate(xmlTextReaderPtr reader, x509certificate_x *x509certificate)
+{
+ xmlTextReaderRead(reader);
+ if (xmlTextReaderValue(reader)) {
+ x509certificate->text = ASCII(xmlTextReaderValue(reader));
+ _d_msg(DEBUG_INFO, "certlen=%d, x509certificate : %s", strlen(x509certificate->text), x509certificate->text);
+ }
+ return 0;
+}
+
+static int _ri_process_x509data(xmlTextReaderPtr reader, x509data_x *x509data)
+{
+ const xmlChar *node = NULL;
+ int ret = 0;
+ int depth = 0;
+ x509certificate_x *tmp1 = NULL;
+
+ depth = xmlTextReaderDepth(reader);
+ while ((ret = _ri_next_child_element(reader, depth))) {
+ node = xmlTextReaderConstName(reader);
+ if (!node) {
+ _d_msg(DEBUG_ERR, "node is NULL\n");
+ return -1;
+ }
+ if (strcmp(ASCII(node), "X509Certificate") == 0) {
+ x509certificate_x *x509certificate = calloc(1, sizeof(x509certificate_x));
+ if (x509certificate == NULL) {
+ _d_msg(DEBUG_ERR, "Calloc Failed\n");
+ return -1;
+ }
+ LISTADD(x509data->x509certificate, x509certificate);
+ ret = _ri_process_x509certificate(reader, x509certificate);
+ } else {
+ _d_msg(DEBUG_INFO, "Invalid tag %s", ASCII(node));
+ return -1;
+ }
+ if (ret < 0)
+ return ret;
+ }
+ if (x509data->x509certificate) {
+ LISTHEAD(x509data->x509certificate, tmp1);
+ x509data->x509certificate = tmp1;
+ }
+ return ret;
+}
+
+#if 0
+static int _ri_process_object(xmlTextReaderPtr reader, object_x *object)
+{
+ /*To be parsed later*/
+ return 0;
+}
+#endif
+
+static int _ri_process_keyinfo(xmlTextReaderPtr reader, keyinfo_x *keyinfo)
+{
+ const xmlChar *node = NULL;
+ int ret = 0;
+ int depth = 0;
+ x509data_x *tmp1 = NULL;
+
+ depth = xmlTextReaderDepth(reader);
+ while ((ret = _ri_next_child_element(reader, depth))) {
+ node = xmlTextReaderConstName(reader);
+ if (!node) {
+ _d_msg(DEBUG_ERR, "node is NULL\n");
+ return -1;
+ }
+ if (strcmp(ASCII(node), "X509Data") == 0) {
+ x509data_x *x509data = calloc(1, sizeof(x509data_x));
+ if (x509data == NULL) {
+ _d_msg(DEBUG_ERR, "Calloc Failed\n");
+ return -1;
+ }
+ LISTADD(keyinfo->x509data, x509data);
+ ret = _ri_process_x509data(reader, x509data);
+ } else {
+ _d_msg(DEBUG_INFO, "Invalid tag %s", ASCII(node));
+ return -1;
+ }
+ if (ret < 0)
+ return ret;
+ }
+ if (keyinfo->x509data) {
+ LISTHEAD(keyinfo->x509data, tmp1);
+ keyinfo->x509data = tmp1;
+ }
+ return ret;
+}
+
+static int _ri_process_signaturevalue(xmlTextReaderPtr reader, signaturevalue_x *signaturevalue)
+{
+ xmlTextReaderRead(reader);
+ if (xmlTextReaderValue(reader)) {
+ signaturevalue->text = ASCII(xmlTextReaderValue(reader));
+ _d_msg(DEBUG_INFO, "siglen=%d SignatureValue %s", strlen(signaturevalue->text), signaturevalue->text);
+ }
+ return 0;
+}
+
+static int _ri_process_signedinfo(xmlTextReaderPtr reader, signedinfo_x *signedinfo)
+{
+ const xmlChar *node = NULL;
+ int ret = 0;
+ int depth = 0;
+ cannonicalizationmethod_x *tmp1 = NULL;
+ signaturemethod_x *tmp2 = NULL;
+ reference_x *tmp3 = NULL;
+
+ depth = xmlTextReaderDepth(reader);
+ while ((ret = _ri_next_child_element(reader, depth))) {
+ node = xmlTextReaderConstName(reader);
+ if (!node) {
+ _d_msg(DEBUG_ERR, "node is NULL\n");
+ return -1;
+ }
+ if (strcmp(ASCII(node), "CanonicalizationMethod") == 0) {
+ cannonicalizationmethod_x *cannonicalizationmethod = calloc(1, sizeof(cannonicalizationmethod_x));
+ if (cannonicalizationmethod == NULL) {
+ _d_msg(DEBUG_ERR, "Calloc Failed\n");
+ return -1;
+ }
+ LISTADD(signedinfo->cannonicalizationmethod, cannonicalizationmethod);
+ ret = _ri_process_cannonicalizationmethod(reader, cannonicalizationmethod);
+ } else if (strcmp(ASCII(node), "SignatureMethod") == 0) {
+ signaturemethod_x *signaturemethod = calloc(1, sizeof(signaturemethod_x));
+ if (signaturemethod == NULL) {
+ _d_msg(DEBUG_ERR, "Calloc Failed\n");
+ return -1;
+ }
+ LISTADD(signedinfo->signaturemethod, signaturemethod);
+ ret = _ri_process_signaturemethod(reader, signaturemethod);
+ } else if (strcmp(ASCII(node), "Reference") == 0) {
+ reference_x *reference = calloc(1, sizeof(reference_x));
+ if (reference == NULL) {
+ _d_msg(DEBUG_ERR, "Calloc Failed\n");
+ return -1;
+ }
+ LISTADD(signedinfo->reference, reference);
+ ret = _ri_process_reference(reader, reference);
+ } else {
+ _d_msg(DEBUG_INFO, "Invalid tag %s", ASCII(node));
+ return -1;
+ }
+ if (ret < 0)
+ return ret;
+ }
+ if (signedinfo->cannonicalizationmethod) {
+ LISTHEAD(signedinfo->cannonicalizationmethod, tmp1);
+ signedinfo->cannonicalizationmethod = tmp1;
+ }
+ if (signedinfo->signaturemethod) {
+ LISTHEAD(signedinfo->signaturemethod, tmp2);
+ signedinfo->signaturemethod = tmp2;
+ }
+ if (signedinfo->reference) {
+ LISTHEAD(signedinfo->reference, tmp3);
+ signedinfo->reference = tmp3;
+ }
+ return ret;
+}
+
+static int _ri_process_sign(xmlTextReaderPtr reader, signature_x *sigx)
+{
+ const xmlChar *node = NULL;
+ int ret = 0;
+ int depth = 0;
+ signedinfo_x *tmp1 = NULL;
+ signaturevalue_x *tmp2 = NULL;
+ keyinfo_x *tmp3 = NULL;
+ object_x *tmp4 = NULL;
+
+ depth = xmlTextReaderDepth(reader);
+ while ((ret = _ri_next_child_element(reader, depth))) {
+ node = xmlTextReaderConstName(reader);
+ if (!node) {
+ _d_msg(DEBUG_ERR, "node is NULL\n");
+ return -1;
+ }
+ if (strcmp(ASCII(node), "SignedInfo") == 0) {
+ signedinfo_x *signedinfo = calloc(1, sizeof(signedinfo_x));
+ if (signedinfo == NULL) {
+ _d_msg(DEBUG_ERR, "Calloc Failed\n");
+ return -1;
+ }
+ LISTADD(sigx->signedinfo, signedinfo);
+ ret = _ri_process_signedinfo(reader, signedinfo);
+ } else if (strcmp(ASCII(node), "SignatureValue") == 0) {
+ signaturevalue_x *signaturevalue = calloc(1, sizeof(signaturevalue_x));
+ if (signaturevalue == NULL) {
+ _d_msg(DEBUG_ERR, "Calloc Failed\n");
+ return -1;
+ }
+ LISTADD(sigx->signaturevalue, signaturevalue);
+ ret = _ri_process_signaturevalue(reader, signaturevalue);
+ } else if (strcmp(ASCII(node), "KeyInfo") == 0) {
+ keyinfo_x *keyinfo = calloc(1, sizeof(keyinfo_x));
+ if (keyinfo == NULL) {
+ _d_msg(DEBUG_ERR, "Calloc Failed\n");
+ return -1;
+ }
+ LISTADD(sigx->keyinfo, keyinfo);
+ ret = _ri_process_keyinfo(reader, keyinfo);
+ } else if (strcmp(ASCII(node), "Object") == 0) {
+ /*
+ object_x *object = calloc(1, sizeof(object_x));
+ if (object == NULL) {
+ _d_msg(DEBUG_ERR, "Calloc Failed\n");
+ return -1;
+ }
+ LISTADD(sigx->object, object);
+ ret = _ri_process_object(reader, object);
+ */
+ continue;
+ } else {
+ _d_msg(DEBUG_INFO, "Invalid tag %s", ASCII(node));
+ return -1;
+ }
+ if (ret < 0)
+ return ret;
+ }
+ if (sigx->signedinfo) {
+ LISTHEAD(sigx->signedinfo, tmp1);
+ sigx->signedinfo = tmp1;
+ }
+ if (sigx->signaturevalue) {
+ LISTHEAD(sigx->signaturevalue, tmp2);
+ sigx->signaturevalue = tmp2;
+ }
+ if (sigx->keyinfo) {
+ LISTHEAD(sigx->keyinfo, tmp3);
+ sigx->keyinfo = tmp3;
+ }
+ if (sigx->object) {
+ LISTHEAD(sigx->object, tmp4);
+ sigx->object = tmp4;
+ }
+ return ret;
+}
+
+static int _ri_process_signature(xmlTextReaderPtr reader, signature_x *sigx)
+{
+ const xmlChar *node = NULL;
+ int ret = -1;
+
+ if ((ret = _ri_next_child_element(reader, -1))) {
+ node = xmlTextReaderConstName(reader);
+ if (!node) {
+ _d_msg(DEBUG_ERR, "Node is null");
+ return -1;
+ }
+ if (!strcmp(ASCII(node), "Signature")) {
+ if (xmlTextReaderGetAttribute(reader, XMLCHAR("Id")))
+ sigx->id = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("Id")));
+ if (xmlTextReaderGetAttribute(reader, XMLCHAR("xmlns")))
+ sigx->xmlns = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("xmlns")));
+ ret = _ri_process_sign(reader, sigx);
+ } else {
+ _d_msg(DEBUG_ERR, "No Signature element found\n");
+ return -1;
+ }
+ }
+ return ret;
+}
+
+signature_x *_ri_process_signature_xml(const char *signature_file)
+{
+ xmlTextReaderPtr reader;
+ signature_x *sigx = NULL;
+
+ reader = xmlReaderForFile(signature_file, NULL, 0);
+
+ if (reader) {
+ sigx = calloc(1, sizeof(signature_x));
+ if (sigx) {
+ if (_ri_process_signature(reader, sigx) < 0) {
+ /* error in parsing. Let's display some hint where we failed */
+ _d_msg(DEBUG_ERR, "Syntax error in processing signature in the above line\n");
+ _ri_free_signature_xml(sigx);
+ xmlFreeTextReader(reader);
+ return NULL;
+ }
+ } else {
+ _d_msg(DEBUG_ERR, "Calloc failed\n");
+ }
+ xmlFreeTextReader(reader);
+ } else {
+ _d_msg(DEBUG_ERR, "Unable to create xml reader\n");
+ }
+ return sigx;
+}
--- /dev/null
+/*
+ * rpm-installer
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
+ * Jaeho Lee <jaeho81.lee@samsung.com>, Shobhit Srivastava <shobhit.s@samsung.com>
+ *
+ * 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.
+ *
+ */
+
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE
+#endif
+#define __USE_GNU
+#include <sys/wait.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <wait.h>
+#include <stdio.h>
+#include <signal.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <glib.h>
+#include <ctype.h> /* for isspace () */
+#include <vconf.h>
+#include <cert-service.h>
+#include <libxml/parser.h>
+#include <libxml/tree.h>
+#include <libxml/xmlmemory.h>
+#ifndef XMLSEC_NO_XSLT
+#include <libxslt/xslt.h>
+#include <libxslt/security.h>
+#endif
+#include <xmlsec/xmlsec.h>
+#include <xmlsec/xmltree.h>
+#include <xmlsec/xmldsig.h>
+#include <xmlsec/crypto.h>
+#include <pkgmgr-info.h>
+#include <pkgmgr_parser.h>
+#include <package-manager.h>
+#include <privilege-control.h>
+#include <app_manager.h>
+#include <aul.h>
+#include <dlfcn.h>
+
+#include "rpm-installer-util.h"
+#include "rpm-installer-signature.h"
+#include "rpm-installer.h"
+#include "rpm-frontend.h"
+#include "rpm-installer-type.h"
+
+#define PRE_CHECK_FOR_MANIFEST
+#define POST_SCRIPT "/usr/bin/post_script_rpm.sh"
+#define INSTALL_SCRIPT "/usr/bin/install_rpm_package.sh"
+#define INSTALL_SCRIPT_WITH_DBPATH_RO "/usr/bin/install_rpm_package_with_dbpath_ro.sh"
+#define INSTALL_SCRIPT_WITH_DBPATH_RW "/usr/bin/install_rpm_package_with_dbpath_rw.sh"
+#define UNINSTALL_SCRIPT "/usr/bin/uninstall_rpm_package.sh"
+#define UPGRADE_SCRIPT "/usr/bin/upgrade_rpm_package.sh"
+#define UPGRADE_SCRIPT_WITH_DBPATH_RO "/usr/bin/upgrade_rpm_package_with_dbpath_ro.sh"
+#define UPGRADE_SCRIPT_WITH_DBPATH_RW "/usr/bin/upgrade_rpm_package_with_dbpath_rw.sh"
+#define TEMP_DBPATH "/opt/usr/rpmdb_tmp"
+
+#define RPM2CPIO "/usr/bin/rpm2cpio"
+#define SIGNATURE1_XML "signature1.xml"
+#define SIGNATURE2_XML "signature2.xml"
+#define AUTHOR_SIGNATURE_XML "author-signature.xml"
+#define USR_APPS "/usr/apps"
+#define OPT_USR_APPS "/opt/usr/apps"
+#define OPT_SHARE_PACKAGES "/opt/share/packages"
+#define USR_SHARE_PACKAGES "/usr/share/packages"
+#define DEACTIVATION_PKGID_LIST "/opt/share/packages/.pkgmgr/rpm-installer/rpm_installer_deactvation_list.txt"
+
+#define OPT_ZIP_FILE "/usr/system/RestoreDir/opt.zip"
+
+#define EFLWGT_TYPE_STR "eflwgt"
+
+#define TOKEN_PACKAGE_STR "package="
+#define TOKEN_PKGID_STR "pkgid="
+#define TOKEN_STATE_STR "state="
+#define TOKEN_PATH_STR "path="
+#define TOKEN_OPERATION_STR "op="
+#define TOKEN_REMOVE_STR "removable="
+#define SEPERATOR_END ':'
+#define SEPERATOR_START '"'
+
+#define APP_OWNER_ID 5000
+#define APP_GROUP_ID 5000
+#define MAX_BUFF_LEN 4096
+#define MAX_CERT_NUM 9
+#define TERMINATE_RETRY_COUNT 100
+
+#define ASC_CHAR(s) (const char *)s
+#define XML_CHAR(s) (const xmlChar *)s
+
+#define BIN_DIR_STR "bin"
+#define RES_DIR_STR "res"
+#define SHARED_RES_DIR_STR "shared/res"
+#define LIBAIL_PATH "/usr/lib/libail.so.0"
+
+enum rpm_request_type {
+ INSTALL_REQ,
+ UNINSTALL_REQ,
+ UPGRADE_REQ,
+};
+
+enum rpm_sig_type {
+ SIG_AUTH,
+ SIG_DIST1,
+ SIG_DIST2,
+};
+
+enum rpm_sig_sub_type {
+ SIG_SIGNER,
+ SIG_INTERMEDIATE,
+ SIG_ROOT,
+};
+
+typedef struct cert_chain_t {
+ int cert_type;
+ char *cert_value;
+} cert_chain;
+
+cert_chain list[MAX_CERT_NUM];
+
+#define APP2EXT_ENABLE
+#ifdef APP2EXT_ENABLE
+#include <app2ext_interface.h>
+#endif
+
+typedef enum rpm_request_type rpm_request_type;
+extern char *gpkgname;
+extern int sig_enable;
+
+static int __rpm_xsystem(const char *argv[]);
+static void __rpm_process_line(char *line);
+static void __rpm_perform_read(int fd);
+static void __rpm_clear_dir_list(GList* dir_list);
+static GList * __rpm_populate_dir_list();
+static int __rpm_delete_dir(char *dirname);
+static int __is_dir(char *dirname);
+static void __rpm_apply_shared_privileges(char *pkgname, int flag);
+static int __ri_xmlsec_verify_signature(const char *sigxmlfile, char *rootca);
+static xmlSecKeysMngrPtr __ri_load_trusted_certs(char *files, int files_size);
+static int __ri_verify_file(xmlSecKeysMngrPtr mngr, const char *sigxmlfile);
+static int __ri_create_cert_chain(int sigtype, int sigsubtype, char *value);
+static void __ri_free_cert_chain(void);
+static char *__ri_get_cert_from_file(const char *file);
+static int __privilege_func(const char *name, void *user_data);
+static char *__ri_get_str(const char* str, const char* pKey);
+static void __ri_xmlsec_debug_print(const char* file, int line, const char* func,
+ const char* errorObject, const char* errorSubject, int reason, const char* msg);
+
+
+static void __str_trim(char *input)
+{
+ char *trim_str = input;
+
+ if (input == NULL)
+ return;
+
+ while (*input != 0) {
+ if (!isspace(*input)) {
+ *trim_str = *input;
+ trim_str++;
+ }
+ input++;
+ }
+
+ *trim_str = 0;
+ return;
+}
+
+static int __ri_check_pkgid_for_deactivation(const char *pkgid)
+{
+ FILE *fp = NULL;
+ char deactivation_str[FILENAME_MAX] = { 0 };
+ char *deactivation_pkgid = NULL;
+ char *deactivation_state = NULL;
+
+ fp = fopen(DEACTIVATION_PKGID_LIST, "r");
+ if (fp == NULL) {
+ _d_msg(DEBUG_ERR, "fopen fail\n");
+ return 0;
+ }
+
+ while (fgets(deactivation_str, sizeof(deactivation_str), fp) != NULL) {
+ __str_trim(deactivation_str);
+
+ deactivation_pkgid = __ri_get_str(deactivation_str, TOKEN_PKGID_STR);
+ if(deactivation_pkgid == NULL)
+ continue;
+
+ deactivation_state = __ri_get_str(deactivation_str, TOKEN_STATE_STR);
+ if(deactivation_state == NULL) {
+ free(deactivation_pkgid);
+ continue;
+ }
+
+ if ((strcmp(deactivation_pkgid, pkgid) == 0) && (strcmp(deactivation_state, "off") == 0)) {
+ fclose(fp);
+ free(deactivation_pkgid);
+ free(deactivation_state);
+ _d_msg(DEBUG_ERR, "Find pkgid[%s] form deactivation list.\n", pkgid);
+ return -1;
+ }
+
+ free(deactivation_pkgid);
+ free(deactivation_state);
+ memset(deactivation_str, 0x00, sizeof(deactivation_str));
+ }
+
+ if (fp != NULL)
+ fclose(fp);
+
+ return 0;
+
+}
+
+static int __ri_get_op_type(char *op_str)
+{
+ if (strcmp(op_str,"install")==0)
+ return INSTALL_REQ;
+ else if (strcmp(op_str,"update")==0)
+ return UPGRADE_REQ;
+ else if (strcmp(op_str,"uninstall")==0)
+ return UNINSTALL_REQ;
+ else
+ return -1;
+}
+
+static char *__ri_get_str(const char* str, const char* pKey)
+{
+ const char* p = NULL;
+ const char* pStart = NULL;
+ const char* pEnd = NULL;
+
+ if (str == NULL)
+ return NULL;
+
+ char *pBuf = strdup(str);
+
+ p = strstr(pBuf, pKey);
+ if (p == NULL)
+ return NULL;
+
+ pStart = p + strlen(pKey);
+ pEnd = strchr(pStart, SEPERATOR_END);
+ if (pEnd == NULL)
+ return false;
+
+ size_t len = pEnd - pStart;
+ if (len <= 0)
+ return false;
+
+ char *pRes = (char*)malloc(len + 1);
+ strncpy(pRes, pStart, len);
+ pRes[len] = 0;
+
+ return pRes;
+}
+
+static int __ri_init_csc_xml(char *xml_path, char *removable)
+{
+ int ret = 0;
+ char* csc_tags[3] = {NULL, };
+
+ if (strcmp(removable,"true")==0)
+ csc_tags[0] = "removable=true";
+ else
+ csc_tags[0] = "removable=false";
+
+ csc_tags[1] = "preload=true";
+ csc_tags[2] = NULL;
+
+ ret = pkgmgr_parser_parse_manifest_for_installation(xml_path, csc_tags);
+
+ return ret;
+}
+
+static int __ri_create_cert_chain(int sigtype, int sigsubtype, char *value)
+{
+ if (value == NULL)
+ return -1;
+ _d_msg(DEBUG_INFO, "Push in list [%d] [%d] [%s]", sigtype, sigsubtype, value);
+ switch (sigtype) {
+ case SIG_AUTH:
+ switch (sigsubtype) {
+ case SIG_SIGNER:
+ list[PMINFO_SET_AUTHOR_SIGNER_CERT].cert_type = PMINFO_SET_AUTHOR_SIGNER_CERT;
+ list[PMINFO_SET_AUTHOR_SIGNER_CERT].cert_value = strdup(value);
+ break;
+ case SIG_INTERMEDIATE:
+ list[PMINFO_SET_AUTHOR_INTERMEDIATE_CERT].cert_type = PMINFO_SET_AUTHOR_INTERMEDIATE_CERT;
+ list[PMINFO_SET_AUTHOR_INTERMEDIATE_CERT].cert_value = strdup(value);
+ break;
+ case SIG_ROOT:
+ /*value is already a mallocd pointer*/
+ list[PMINFO_SET_AUTHOR_ROOT_CERT].cert_type = PMINFO_SET_AUTHOR_ROOT_CERT;
+ list[PMINFO_SET_AUTHOR_ROOT_CERT].cert_value = value;
+ break;
+ default:
+ break;
+ }
+ break;
+ case SIG_DIST1:
+ switch (sigsubtype) {
+ case SIG_SIGNER:
+ list[PMINFO_SET_DISTRIBUTOR_SIGNER_CERT].cert_type = PMINFO_SET_DISTRIBUTOR_SIGNER_CERT;
+ list[PMINFO_SET_DISTRIBUTOR_SIGNER_CERT].cert_value = strdup(value);
+ break;
+ case SIG_INTERMEDIATE:
+ list[PMINFO_SET_DISTRIBUTOR_INTERMEDIATE_CERT].cert_type = PMINFO_SET_DISTRIBUTOR_INTERMEDIATE_CERT;
+ list[PMINFO_SET_DISTRIBUTOR_INTERMEDIATE_CERT].cert_value = strdup(value);
+ break;
+ case SIG_ROOT:
+ /*value is already a mallocd pointer*/
+ list[PMINFO_SET_DISTRIBUTOR_ROOT_CERT].cert_type = PMINFO_SET_DISTRIBUTOR_ROOT_CERT;
+ list[PMINFO_SET_DISTRIBUTOR_ROOT_CERT].cert_value = value;
+ break;
+ default:
+ break;
+ }
+ break;
+ case SIG_DIST2:
+ switch (sigsubtype) {
+ case SIG_SIGNER:
+ list[PMINFO_SET_DISTRIBUTOR2_SIGNER_CERT].cert_type = PMINFO_SET_DISTRIBUTOR2_SIGNER_CERT;
+ list[PMINFO_SET_DISTRIBUTOR2_SIGNER_CERT].cert_value = strdup(value);
+ break;
+ case SIG_INTERMEDIATE:
+ list[PMINFO_SET_DISTRIBUTOR2_INTERMEDIATE_CERT].cert_type = PMINFO_SET_DISTRIBUTOR2_INTERMEDIATE_CERT;
+ list[PMINFO_SET_DISTRIBUTOR2_INTERMEDIATE_CERT].cert_value = strdup(value);
+ break;
+ case SIG_ROOT:
+ /*value is already a mallocd pointer*/
+ list[PMINFO_SET_DISTRIBUTOR2_ROOT_CERT].cert_type = PMINFO_SET_DISTRIBUTOR2_ROOT_CERT;
+ list[PMINFO_SET_DISTRIBUTOR2_ROOT_CERT].cert_value = value;
+ break;
+ default:
+ break;
+ }
+ break;
+ default:
+ break;
+ }
+ return 0;
+}
+
+static void __ri_free_cert_chain()
+{
+ int i = 0;
+ for (i = 0; i < MAX_CERT_NUM; i++) {
+ if (list[i].cert_value)
+ free(list[i].cert_value);
+ }
+}
+
+static void __ri_xmlsec_debug_print(const char* file, int line, const char* func,
+ const char* errorObject, const char* errorSubject, int reason, const char* msg)
+{
+ char total[BUF_SIZE];
+ snprintf(total, sizeof(total), "[%s(%d)] : [%s] : [%s] : [%s]", func, line, errorObject, errorSubject, msg);
+ if(reason != 256) {
+ fprintf(stderr, "## [validate error]: %s\n", total);
+ _d_msg(DEBUG_ERR,"%s",total);
+ } else {
+ _d_msg(DEBUG_ERR,"%s",total);
+ }
+}
+
+static int __ri_verify_file(xmlSecKeysMngrPtr sec_key_mngr, const char *sigxmlfile)
+{
+ xmlDocPtr doc = NULL;
+ xmlNodePtr node = NULL;
+ xmlSecDSigCtxPtr dsigCtx = NULL;
+ int res = -1;
+ if (sigxmlfile == NULL)
+ return -1;
+ if (sec_key_mngr == NULL)
+ return -1;
+
+ /* set error callback to xmlsec1 */
+ xmlSecErrorsSetCallback(__ri_xmlsec_debug_print);
+
+ /* load file */
+ doc = xmlParseFile(sigxmlfile);
+ if ((doc == NULL) || (xmlDocGetRootElement(doc) == NULL)) {
+ _d_msg(DEBUG_ERR, "unable to parse file \"%s\"\n", sigxmlfile);
+ goto err;
+ }
+ /* find start node */
+ node = xmlSecFindNode(xmlDocGetRootElement(doc), xmlSecNodeSignature, xmlSecDSigNs);
+ if (node == NULL) {
+ _d_msg(DEBUG_ERR, "start node not found in \"%s\"\n", sigxmlfile);
+ goto err;
+ }
+ /* create signature context */
+ dsigCtx = xmlSecDSigCtxCreate(sec_key_mngr);
+ if (dsigCtx == NULL) {
+ _d_msg(DEBUG_ERR, "failed to create signature context\n");
+ goto err;
+ }
+ /* Verify signature */
+ if (xmlSecDSigCtxVerify(dsigCtx, node) < 0) {
+ _d_msg(DEBUG_ERR, "failed to verify signature\n");
+ goto err;
+ }
+ /* print verification result to stdout */
+ if (dsigCtx->status == xmlSecDSigStatusSucceeded) {
+ res = 0;
+ _d_msg(DEBUG_INFO, "Signature VALID");
+ } else {
+ res = -1;
+ _d_msg(DEBUG_INFO, "Signature INVALID");
+ }
+
+err:
+ /* cleanup */
+ if(dsigCtx != NULL) {
+ xmlSecDSigCtxDestroy(dsigCtx);
+ }
+ if(doc != NULL) {
+ xmlFreeDoc(doc);
+ }
+ return res;
+}
+
+static xmlSecKeysMngrPtr __ri_load_trusted_certs(char *files, int files_size)
+{
+ xmlSecKeysMngrPtr sec_key_mngr;
+ if (files == NULL)
+ return NULL;
+ if (files_size < 0)
+ return NULL;
+ sec_key_mngr = xmlSecKeysMngrCreate();
+ if (sec_key_mngr == NULL) {
+ _d_msg(DEBUG_ERR, "failed to create keys manager.\n");
+ return NULL;
+ }
+ if (xmlSecCryptoAppDefaultKeysMngrInit(sec_key_mngr) < 0) {
+ _d_msg(DEBUG_ERR, "failed to initialize keys manager.\n");
+ xmlSecKeysMngrDestroy(sec_key_mngr);
+ return NULL;
+ }
+ /* load trusted cert */
+ if (xmlSecCryptoAppKeysMngrCertLoad(sec_key_mngr, files, xmlSecKeyDataFormatPem, xmlSecKeyDataTypeTrusted) < 0) {
+ _d_msg(DEBUG_ERR, "failed to load pem certificate from \"%s\"\n", files);
+ xmlSecKeysMngrDestroy(sec_key_mngr);
+ return NULL;
+ }
+ return sec_key_mngr;
+}
+
+static int __ri_xmlsec_verify_signature(const char *sigxmlfile, char *rootca)
+{
+ int ret = 0;
+ xmlSecKeysMngrPtr sec_key_mngr = NULL;
+ xmlInitParser();
+ xmlLoadExtDtdDefaultValue = XML_DETECT_IDS | XML_COMPLETE_ATTRS;
+ xmlSubstituteEntitiesDefault(1);
+
+#ifndef XMLSEC_NO_XSLT
+ xmlIndentTreeOutput = 1;
+ xsltSecurityPrefsPtr sec_prefs = xsltNewSecurityPrefs();
+ xsltSetSecurityPrefs(sec_prefs, XSLT_SECPREF_WRITE_FILE, xsltSecurityForbid);
+ xsltSetSecurityPrefs(sec_prefs, XSLT_SECPREF_READ_FILE, xsltSecurityForbid);
+ xsltSetSecurityPrefs(sec_prefs, XSLT_SECPREF_CREATE_DIRECTORY, xsltSecurityForbid);
+ xsltSetSecurityPrefs(sec_prefs, XSLT_SECPREF_WRITE_NETWORK, xsltSecurityForbid);
+ xsltSetSecurityPrefs(sec_prefs, XSLT_SECPREF_READ_NETWORK, xsltSecurityForbid);
+ xsltSetDefaultSecurityPrefs(sec_prefs);
+#endif
+
+ ret = xmlSecInit();
+ if (ret < 0) {
+ _d_msg(DEBUG_ERR, "xmlsec initialization failed [%d]\n", ret);
+ goto end;
+ }
+ ret = xmlSecCheckVersion();
+ if (ret != 1) {
+ _d_msg(DEBUG_ERR, "Incompatible version of loaded xmlsec library [%d]\n", ret);
+ goto end;
+ }
+#ifdef XMLSEC_CRYPTO_DYNAMIC_LOADING
+ ret = xmlSecCryptoDLLoadLibrary(BAD_CAST "openssl");
+ if (ret < 0) {
+ _d_msg(DEBUG_ERR, "unable to load openssl library [%d]\n", ret);
+ goto end;
+ }
+#endif
+
+ ret = xmlSecCryptoAppInit(NULL);
+ if (ret < 0) {
+ _d_msg(DEBUG_ERR, "crypto initialization failed [%d]\n", ret);
+ goto end;
+ }
+ ret = xmlSecCryptoInit();
+ if (ret < 0) {
+ _d_msg(DEBUG_ERR, "xmlsec-crypto initialization failed [%d]\n", ret);
+ goto end;
+ }
+
+ sec_key_mngr = __ri_load_trusted_certs(rootca, 1);
+ if (sec_key_mngr == NULL) {
+ _d_msg(DEBUG_ERR, "loading of trusted certs failed\n");
+ ret = -1;
+ goto end;
+ }
+
+ if (__ri_verify_file(sec_key_mngr, sigxmlfile) < 0) {
+ ret = -1;
+ }
+
+end:
+ if (sec_key_mngr)
+ xmlSecKeysMngrDestroy(sec_key_mngr);
+ xmlSecCryptoShutdown();
+ xmlSecCryptoAppShutdown();
+ xmlSecShutdown();
+#ifndef XMLSEC_NO_XSLT
+ xsltFreeSecurityPrefs(sec_prefs);
+ xsltCleanupGlobals();
+#endif
+ xmlCleanupParser();
+ return ret;
+}
+
+static void __rpm_apply_shared_privileges(char *pkgname, int flag)
+{
+ int ret = -1;
+ char buf[BUF_SIZE] = {'\0'};
+ char dirpath[BUF_SIZE] = {'\0'};
+ /*execute privilege APIs. The APIs should not fail*/
+ _ri_privilege_register_package(pkgname);
+
+ /*home dir. Dont setup path but change smack access to "_" */
+ snprintf(dirpath, BUF_SIZE, "/usr/apps/%s", pkgname);
+ if (__is_dir(dirpath))
+ _ri_privilege_change_smack_label(dirpath, "_", 0);/*0 is SMACK_LABEL_ACCESS*/
+ memset(dirpath, '\0', BUF_SIZE);
+ snprintf(dirpath, BUF_SIZE, "/opt/usr/apps/%s", pkgname);
+ if (__is_dir(dirpath))
+ _ri_privilege_change_smack_label(dirpath, "_", 0);/*0 is SMACK_LABEL_ACCESS*/
+ memset(dirpath, '\0', BUF_SIZE);
+
+ /*/shared dir. Dont setup path but change smack access to "_" */
+ snprintf(dirpath, BUF_SIZE, "/usr/apps/%s/shared", pkgname);
+ if (__is_dir(dirpath))
+ _ri_privilege_change_smack_label(dirpath, "_", 0);/*0 is SMACK_LABEL_ACCESS*/
+ memset(dirpath, '\0', BUF_SIZE);
+ snprintf(dirpath, BUF_SIZE, "/opt/usr/apps/%s/shared", pkgname);
+ if (__is_dir(dirpath))
+ _ri_privilege_change_smack_label(dirpath, "_", 0);/*0 is SMACK_LABEL_ACCESS*/
+ memset(dirpath, '\0', BUF_SIZE);
+
+ /*/shared/res dir. setup path and change smack access to "_" */
+ snprintf(dirpath, BUF_SIZE, "/usr/apps/%s/shared/res", pkgname);
+ if (__is_dir(dirpath))
+ _ri_privilege_setup_path(pkgname, dirpath, PERM_APP_PATH_ANY_LABEL, "_");
+ memset(dirpath, '\0', BUF_SIZE);
+
+ snprintf(dirpath, BUF_SIZE, "/opt/usr/apps/%s/shared/res", pkgname);
+ if (__is_dir(dirpath))
+ _ri_privilege_setup_path(pkgname, dirpath, PERM_APP_PATH_ANY_LABEL, "_");
+ memset(dirpath, '\0', BUF_SIZE);
+
+ /*/shared/data dir. setup path and change group to 'app'*/
+ snprintf(dirpath, BUF_SIZE, "/usr/apps/%s/shared/data", pkgname);
+ if (__is_dir(dirpath)) {
+ (void)chown(dirpath, APP_OWNER_ID, APP_GROUP_ID);
+ _ri_privilege_setup_path(pkgname, dirpath, PERM_APP_PATH_PUBLIC, NULL);
+ }
+ memset(dirpath, '\0', BUF_SIZE);
+
+ snprintf(dirpath, BUF_SIZE, "/opt/usr/apps/%s/shared/data", pkgname);
+ if (__is_dir(dirpath)) {
+ (void)chown(dirpath, APP_OWNER_ID, APP_GROUP_ID);
+ _ri_privilege_setup_path(pkgname, dirpath, PERM_APP_PATH_PUBLIC, NULL);
+ }
+}
+
+static int __is_dir(char *dirname)
+{
+ struct stat stFileInfo;
+ if(dirname == NULL) {
+ _d_msg(DEBUG_ERR, "dirname is null\n");
+ return -1;
+ }
+
+ (void)stat(dirname, &stFileInfo);
+
+ if (S_ISDIR(stFileInfo.st_mode)) {
+ return 1;
+ }
+ return 0;
+}
+
+static int __rpm_delete_dir(char *dirname)
+{
+ int ret = 0;
+ DIR *dp;
+ struct dirent *ep;
+ char abs_filename[FILENAME_MAX];
+ struct stat stFileInfo;
+ dp = opendir(dirname);
+
+ _d_msg(DEBUG_INFO, "__rpm_delete_dir(%s)\n", dirname);
+
+ if (dp != NULL) {
+ while ((ep = readdir(dp))) {
+ snprintf(abs_filename, FILENAME_MAX, "%s/%s", dirname,
+ ep->d_name);
+ if (lstat(abs_filename, &stFileInfo) < 0)
+ perror(abs_filename);
+ if (S_ISDIR(stFileInfo.st_mode)) {
+ if (strcmp(ep->d_name, ".") &&
+ strcmp(ep->d_name, "..")) {
+ __rpm_delete_dir(abs_filename);
+ (void)remove(abs_filename);
+ }
+ } else {
+ (void)remove(abs_filename);
+ }
+ }
+ (void)closedir(dp);
+ } else {
+ _d_msg(DEBUG_ERR, "Couldn't open the directory\n");
+ return -1;
+ }
+ ret = remove(dirname);
+ if (ret < 0)
+ _d_msg(DEBUG_ERR, "remove fail dirname[%s]\n", dirname);
+
+ return 0;
+}
+
+
+static void __rpm_process_line(char *line)
+{
+ char *tok = NULL;
+ tok = strtok(line, " ");
+ if (tok) {
+ if (!strncmp(tok, "%%", 2)) {
+ tok = strtok(NULL, " ");
+ if (tok) {
+ _d_msg(DEBUG_INFO, "Install percentage is %s\n",
+ tok);
+ _ri_broadcast_status_notification(gpkgname,
+ "install_percent",
+ tok);
+ _ri_stat_cb(gpkgname, "install_percent", tok);
+ }
+ return;
+ }
+ }
+ return;
+}
+
+static void __rpm_perform_read(int fd)
+{
+ char *buf_ptr = NULL;
+ char *tmp_ptr = NULL;
+ int size = 0;
+ static char buffer[BUF_SIZE] = { 0, };
+ static int buffer_position;
+
+ size = read(fd, &buffer[buffer_position],
+ sizeof(buffer) - buffer_position);
+ buffer_position += size;
+ if (size <= 0)
+ return;
+
+ /* Process each line of the recieved buffer */
+ buf_ptr = tmp_ptr = buffer;
+ while ((tmp_ptr = (char *)memchr(buf_ptr, '\n',
+ buffer + buffer_position - buf_ptr)) !=
+ NULL) {
+ *tmp_ptr = 0;
+ __rpm_process_line(buf_ptr);
+ /* move to next line and continue */
+ buf_ptr = tmp_ptr + 1;
+ }
+
+ /*move the remaining bits at the start of the buffer
+ and update the buffer position */
+ buf_ptr = (char *)memrchr(buffer, 0, buffer_position);
+ if (buf_ptr == NULL)
+ return;
+
+ /* we have processed till the last \n which has now become
+ 0x0. So we increase the pointer to next position */
+ buf_ptr++;
+
+ memmove(buffer, buf_ptr, buf_ptr - buffer);
+ buffer_position = buffer + buffer_position - buf_ptr;
+}
+
+static int __ri_xsystem(const char *argv[])
+{
+ int status = 0;
+ pid_t pid;
+ pid = fork();
+ switch (pid) {
+ case -1:
+ perror("fork failed");
+ return -1;
+ case 0:
+ /* child */
+ execvp(argv[0], (char *const *)argv);
+ _exit(-1);
+ default:
+ /* parent */
+ break;
+ }
+ if (waitpid(pid, &status, 0) == -1) {
+ perror("waitpid failed");
+ return -1;
+ }
+ if (WIFSIGNALED(status)) {
+ perror("signal");
+ return -1;
+ }
+ if (!WIFEXITED(status)) {
+ /* shouldn't happen */
+ perror("should not happen");
+ return -1;
+ }
+ return WEXITSTATUS(status);
+}
+
+static int __rpm_xsystem(const char *argv[])
+{
+ int err = 0;
+ int status = 0;
+ pid_t pid;
+ int pipefd[2];
+ int result = 0;
+ int fd = 0;
+
+ if (pipe(pipefd) == -1) {
+ _d_msg(DEBUG_ERR, "pipe creation failed\n");
+ return -1;
+ }
+ /*Read progress info via pipe */
+ pid = fork();
+
+ switch (pid) {
+ case -1:
+ _d_msg(DEBUG_ERR, "fork failed\n");
+ return -1;
+ case 0:
+ /* child */
+ {
+ close(pipefd[0]);
+ close(1);
+ close(2);
+ fd = dup(pipefd[1]);
+ if (fd < 0) {
+ _d_msg(DEBUG_ERR, "dup failed\n");
+ _exit(100);
+ }
+
+ result = dup(pipefd[1]);
+ if (result < 0) {
+ _d_msg(DEBUG_ERR, "dup failed\n");
+ _exit(100);
+ }
+
+ if (execvp(argv[0], (char *const *)argv) == -1) {
+ _d_msg(DEBUG_ERR, "execvp failed\n");
+ }
+ _exit(100);
+ }
+ default:
+ /* parent */
+ break;
+ }
+
+ close(pipefd[1]);
+
+ while ((err = waitpid(pid, &status, WNOHANG)) != pid) {
+ if (err < 0) {
+ if (errno == EINTR)
+ continue;
+ _d_msg(DEBUG_ERR, "waitpid failed\n");
+ close(pipefd[0]);
+ return -1;
+ }
+
+ int select_ret;
+ fd_set rfds;
+ struct timespec tv;
+ FD_ZERO(&rfds);
+ FD_SET(pipefd[0], &rfds);
+ tv.tv_sec = 1;
+ tv.tv_nsec = 0;
+ select_ret =
+ pselect(pipefd[0] + 1, &rfds, NULL, NULL, &tv, NULL);
+ if (select_ret == 0)
+ continue;
+
+ else if (select_ret < 0 && errno == EINTR)
+ continue;
+ else if (select_ret < 0) {
+ _d_msg(DEBUG_ERR, "select() returned error\n");
+ continue;
+ }
+ if (FD_ISSET(pipefd[0], &rfds))
+ __rpm_perform_read(pipefd[0]);
+ }
+
+ close(pipefd[0]);
+ /* Check for an error code. */
+ if (WIFEXITED(status) == 0 || WEXITSTATUS(status) != 0) {
+
+ if (WIFSIGNALED(status) != 0 && WTERMSIG(status) == SIGSEGV) {
+ printf
+ ("Sub-process %s received a segmentation fault. \n",
+ argv[0]);
+ } else if (WIFEXITED(status) != 0) {
+ printf("Sub-process %s returned an error code (%u)\n",
+ argv[0], WEXITSTATUS(status));
+ } else {
+ printf("Sub-process %s exited unexpectedly\n", argv[0]);
+ }
+ }
+ return WEXITSTATUS(status);
+}
+
+static void __rpm_clear_dir_list(GList* dir_list)
+{
+ GList *list = NULL;
+ app2ext_dir_details* dir_detail = NULL;
+ if (dir_list) {
+ list = g_list_first(dir_list);
+ while (list) {
+ dir_detail = (app2ext_dir_details *)list->data;
+ if (dir_detail && dir_detail->name) {
+ free(dir_detail->name);
+ }
+ list = g_list_next(list);
+ }
+ g_list_free(dir_list);
+ }
+}
+
+static GList * __rpm_populate_dir_list()
+{
+ GList *dir_list = NULL;
+ GList *list = NULL;
+ app2ext_dir_details* dir_detail = NULL;
+ int i;
+ char pkg_ro_content_rpm[3][5] = { "bin", "res", "lib" };
+
+
+ for (i=0; i<3; i++) {
+ dir_detail = (app2ext_dir_details*) calloc(1, sizeof(app2ext_dir_details));
+ if (dir_detail == NULL) {
+ printf("\nMemory allocation failed\n");
+ goto FINISH_OFF;
+ }
+ dir_detail->name = (char*) calloc(1, sizeof(char)*(strlen(pkg_ro_content_rpm[i])+2));
+ if (dir_detail->name == NULL) {
+ printf("\nMemory allocation failed\n");
+ free(dir_detail);
+ goto FINISH_OFF;
+ }
+ snprintf(dir_detail->name, (strlen(pkg_ro_content_rpm[i])+1), "%s", pkg_ro_content_rpm[i]);
+ dir_detail->type = APP2EXT_DIR_RO;
+ dir_list = g_list_append(dir_list, dir_detail);
+ }
+ if (dir_list) {
+ list = g_list_first(dir_list);
+ while (list) {
+ dir_detail = (app2ext_dir_details *)list->data;
+ list = g_list_next(list);
+ }
+ }
+ return dir_list;
+FINISH_OFF:
+ if (dir_list) {
+ list = g_list_first(dir_list);
+ while (list) {
+ dir_detail = (app2ext_dir_details *)list->data;
+ if (dir_detail && dir_detail->name) {
+ free(dir_detail->name);
+ }
+ list = g_list_next(list);
+ }
+ g_list_free(dir_list);
+ }
+ return NULL;
+}
+
+static char *__ri_get_cert_from_file(const char *file)
+{
+ FILE *fp_cert = NULL;
+ int certlen = 0;
+ char *certbuf = NULL;
+ char *startcert = NULL;
+ char *endcert = NULL;
+ int certwrite = 0;
+ char *cert = NULL;
+ int i = 0;
+ int ch = 0;
+ int error = 0;
+
+ if(!(fp_cert = fopen(file, "r"))) {
+ _d_msg(DEBUG_ERR, "[ERR][%s] Fail to open file, [%s]\n", __func__, file);
+ return NULL;
+ }
+
+ fseek(fp_cert, 0L, SEEK_END);
+
+ if(ftell(fp_cert) < 0) {
+ _d_msg(DEBUG_ERR, "[ERR][%s] Fail to find EOF\n", __func__);
+ error = 1;
+ goto err;
+ }
+
+ certlen = ftell(fp_cert);
+ fseek(fp_cert, 0L, SEEK_SET);
+
+ if(!(certbuf = (char*)malloc(sizeof(char) * (int)certlen))) {
+ _d_msg(DEBUG_ERR, "[ERR][%s] Fail to allocate memory\n", __func__);
+ error = 1;
+ goto err;
+ }
+ memset(certbuf, 0x00, (int)certlen);
+
+ i = 0;
+ while((ch = fgetc(fp_cert)) != EOF) {
+ if(ch != '\n') {
+ certbuf[i] = ch;
+ i++;
+ }
+ }
+ certbuf[i] = '\0';
+
+ startcert = strstr(certbuf, "-----BEGIN CERTIFICATE-----") + strlen("-----BEGIN CERTIFICATE-----");
+ endcert = strstr(certbuf, "-----END CERTIFICATE-----");
+ certwrite = (int)endcert - (int)startcert;
+
+ cert = (char*)malloc(sizeof(char) * (certwrite+2));
+ if (cert == NULL) {
+ _d_msg(DEBUG_ERR, "[ERR][%s] Fail to allocate memory\n", __func__);
+ error = 1;
+ goto err;
+ }
+ memset(cert, 0x00, certwrite+2);
+ snprintf(cert, certwrite+1, "%s", startcert);
+ _d_msg(DEBUG_INFO, "Root CA : %s", cert);
+
+err:
+ if (certbuf)
+ free(certbuf);
+ fclose(fp_cert);
+ if (error)
+ return NULL;
+ else
+ return cert;
+}
+
+static int __privilege_func(const char *name, void *user_data)
+{
+ int ret = 0;
+ const char *perm[] = {NULL, NULL};
+ perm[0] = name;
+
+ ret = _ri_privilege_enable_permissions((char *)user_data, 7, perm, 1);
+ if(ret < 0) {
+ _d_msg(DEBUG_ERR, "%s enable_permissions[%s] fail \n", user_data, perm);
+ }
+
+ return ret;
+}
+
+char* __manifest_to_package(const char* manifest)
+{
+ char *package;
+
+ if(manifest == NULL)
+ return NULL;
+
+ package = strdup(manifest);
+ if(package == NULL)
+ return NULL;
+
+ if (!strstr(package, ".xml")) {
+ _d_msg(DEBUG_ERR, "%s is not a manifest file", manifest);
+ free(package);
+ return NULL;
+ }
+
+ return package;
+}
+
+char *__strlwr(char *str)
+{
+ int i = 0;
+
+ while(*(str+i) != NULL){
+ if(*(str+i) >= 65 || *(str+i)<= 90) {
+ *(str+i) = towlower(*(str+i));
+ }
+ i++;
+ }
+ return str;
+}
+
+static int __ri_find_xml(char *pkgid, char **rpm_xml)
+{
+ DIR *dir;
+ struct dirent entry, *result;
+ int ret = 0;
+ char buf[BUF_SIZE];
+
+ dir = opendir(USR_SHARE_PACKAGES);
+ if (!dir) {
+ if (strerror_r(errno, buf, sizeof(buf)) == 0)
+ _d_msg(DEBUG_ERR, "fota-info : Failed to access the [%s] because %s", USR_SHARE_PACKAGES, buf);
+ return -1;
+ }
+
+ for (ret = readdir_r(dir, &entry, &result);
+ ret == 0 && result != NULL;
+ ret = readdir_r(dir, &entry, &result)) {
+ char *manifest;
+
+ if (entry.d_name[0] == '.') continue;
+
+ manifest = __manifest_to_package(entry.d_name);
+ if (!manifest) {
+ _d_msg(DEBUG_ERR, "fota-info : Failed to convert file to xml[%s]", entry.d_name);
+ continue;
+ }
+
+ if (strstr(manifest, __strlwr(pkgid))) {
+ snprintf(buf, sizeof(buf), "%s/%s", USR_SHARE_PACKAGES, manifest);
+ _d_msg(DEBUG_INFO, "fota-info : pkgid[%s] find xml[%s]\n", pkgid, buf);
+ *rpm_xml = strdup(buf);
+ closedir(dir);
+ return 0;
+ }
+ }
+
+ _d_msg(DEBUG_ERR, "fota-info : Failed to find xml for pkgid[%s]", pkgid);
+ closedir(dir);
+ return 0;
+}
+
+static int __ri_install_fota(char *pkgid)
+{
+ int ret = 0;
+ char *manifest = NULL;
+
+ _d_msg(DEBUG_INFO, "fota-info : pkgid[%s] start installation\n", pkgid);
+
+ /*if pkgid is one of deactivation, it does not need to install*/
+ ret = __ri_check_pkgid_for_deactivation(pkgid);
+ if (ret < 0) {
+ _d_msg(DEBUG_ERR, "fota-info : pkgid[%s] for deactivation dont need to install.\n", pkgid);
+ return ret;
+ }
+
+ /*get manifest*/
+ manifest = pkgmgr_parser_get_manifest_file(pkgid);
+ if (manifest == NULL) {
+ _d_msg(DEBUG_ERR, "fota-info : dont have manefest[pkgid=%s]\n", pkgid);
+ ret = -1;
+ goto end;
+ }
+ _d_msg(DEBUG_INFO, "fota-info : pkgid[%s] has manefest[%s]\n", pkgid, manifest);
+
+ ret = pkgmgr_parser_parse_manifest_for_installation(manifest, NULL);
+ if (ret < 0) {
+ _d_msg(DEBUG_ERR, "fota-info : installation fail[manifest=%s]\n", manifest);
+ ret = -1;
+ goto end;
+ }
+ _d_msg(DEBUG_INFO, "fota-info : pkgid[%s] installation success\n", pkgid);
+
+ __rpm_apply_shared_privileges(pkgid,0);
+
+ ret = _ri_apply_perm(pkgid);
+ if (ret < 0) {
+ _d_msg(DEBUG_ERR, "fota-info : _ri_apply_perm fail[pkgid=%s]\n", pkgid);
+ ret = -1;
+ goto end;
+ }
+ _d_msg(DEBUG_INFO, "fota-info : pkgid[%s] apply smack success\n", pkgid);
+
+end:
+ if (manifest)
+ free(manifest);
+
+ return ret;
+}
+
+static int __ri_upgrade_fota(char *pkgid)
+{
+ _d_msg(DEBUG_INFO, "fota-info : pkgid[%s] start upgrade\n", pkgid);
+
+ int ret = 0;
+ char *manifest = NULL;
+
+ /*if pkgid is one of deactivation, it does not need to upgrade*/
+ ret = __ri_check_pkgid_for_deactivation(pkgid);
+ if (ret < 0) {
+ _d_msg(DEBUG_ERR, "fota-info : pkgid[%s] for deactivation dont need to install.\n", pkgid);
+ return ret;
+ }
+
+ /*get manifest*/
+ manifest = pkgmgr_parser_get_manifest_file(pkgid);
+ if (manifest == NULL) {
+ _d_msg(DEBUG_ERR, "fota-info : dont have manefest[pkgid=%s]\n", pkgid);
+ ret = -1;
+ goto end;
+ }
+ _d_msg(DEBUG_INFO, "fota-info : pkgid[%s] has manefest[%s]\n", pkgid, manifest);
+ if (access(manifest, F_OK) != 0) {
+ _d_msg(DEBUG_ERR, "fota-info : can not access[manifest=%s]\n", manifest);
+ free(manifest);
+ manifest = NULL;
+
+ /*find xml*/
+ ret = __ri_find_xml(pkgid, &manifest);
+ if (ret < 0) {
+ _d_msg(DEBUG_ERR, "fota-info : can not find xml[pkgid=%s]\n", pkgid);
+ ret = -1;
+ goto end;
+ }
+ }
+
+ if (manifest == NULL) {
+ return -1;
+ }
+
+ ret = pkgmgr_parser_parse_manifest_for_upgrade(manifest, NULL);
+ if (ret < 0) {
+ _d_msg(DEBUG_ERR, "fota-info : upgrade fail[manifest=%s]\n", manifest);
+ ret = -1;
+ goto end;
+ }
+ _d_msg(DEBUG_INFO, "fota-info : pkgid[%s] upgrade success\n", pkgid);
+
+end:
+ if (manifest)
+ free(manifest);
+
+ return ret;
+}
+
+static int __ri_uninstall_fota(char *pkgid)
+{
+ _d_msg(DEBUG_INFO, "fota-info : pkgid[%s] start uninstallation\n", pkgid);
+
+ int ret = 0;
+
+ ret = _ri_privilege_unregister_package(pkgid);
+ if (ret < 0) {
+ _d_msg(DEBUG_ERR, "fota-info : _ri_privilege_unregister_package fail[pkgid=%s]\n", pkgid);
+ }
+
+ ret = pkgmgr_parser_parse_manifest_for_uninstallation(pkgid, NULL);
+ if (ret < 0) {
+ _d_msg(DEBUG_ERR, "fota-info : uninstall fail[manifest=%s]\n", pkgid);
+ }
+
+ _d_msg(DEBUG_INFO, "fota-info : pkgid[%s] uninstall success\n", pkgid);
+
+ return ret;
+}
+
+static char * __getvalue(const char* pBuf, const char* pKey)
+{
+ const char* p = NULL;
+ const char* pStart = NULL;
+ const char* pEnd = NULL;
+
+ p = strstr(pBuf, pKey);
+ if (p == NULL)
+ return NULL;
+
+ pStart = p + strlen(pKey) + 1;
+ pEnd = strchr(pStart, SEPERATOR_START);
+ if (pEnd == NULL)
+ return NULL;
+
+ size_t len = pEnd - pStart;
+ if (len <= 0)
+ return NULL;
+
+ char *pRes = (char*)malloc(len + 1);
+ strncpy(pRes, pStart, len);
+ pRes[len] = 0;
+
+ return pRes;
+}
+
+static char *__find_rpm_pkgid(const char* manifest)
+{
+ FILE *fp = NULL;
+ char buf[BUF_SIZE] = {0};
+ char *pkgid = NULL;
+
+ fp = fopen(manifest, "r");
+ if (fp == NULL) {
+ _d_msg(DEBUG_ERR, "csc-info : Fail get : %s\n", manifest);
+ return NULL;
+ }
+
+ while (fgets(buf, BUF_SIZE, fp) != NULL) {
+ __str_trim(buf);
+ pkgid = __getvalue(buf, TOKEN_PACKAGE_STR);
+ if (pkgid != NULL) {
+ fclose(fp);
+ return pkgid;
+ }
+ memset(buf, 0x00, BUF_SIZE);
+ }
+
+ if (fp != NULL)
+ fclose(fp);
+
+ return NULL;
+}
+
+static int __copy_file( const char *src_path, const char *dst_path)
+{
+ FILE *src, *dst;
+ int rc = 0;
+ unsigned char temp_buf[8192] = {'\0',};
+ size_t size_of_uchar = sizeof( unsigned char);
+ size_t size_of_temp_buf = sizeof( temp_buf);
+
+ src = fopen(src_path, "r");
+ if( src == NULL) {
+ _d_msg(DEBUG_ERR, "Failed to open(). path=%s, E:%d(%s)", src_path, errno, strerror(errno));
+ return -1;
+ }
+
+ dst = fopen(dst_path, "w");
+ if( dst == NULL) {
+ _d_msg(DEBUG_ERR, "Failed to open dst file. file=%s, E:%d(%s)", dst_path, errno, strerror(errno));
+ fclose(src);
+ return -1;
+ }
+
+ while(!feof(src)) {
+ rc = fread( temp_buf, size_of_uchar, size_of_temp_buf, src);
+ fwrite( temp_buf, size_of_uchar, rc, dst);
+ }
+
+ fclose( src);
+ fclose( dst);
+ return 0;
+}
+
+static int __ri_install_csc(char *path_str, char *remove_str)
+{
+ int ret = 0;
+
+ char *pkgid = NULL;
+ char delims[] = "/";
+ char* token = NULL;
+ char argv[BUF_SIZE] = {'\0'};
+ char xml_name[BUF_SIZE] = {'\0'};
+ char src_file[BUF_SIZE] = {'\0'};
+ char dest_file[BUF_SIZE] = {'\0'};
+
+ snprintf(src_file, sizeof(src_file), "%s", path_str);
+
+ /*get pkgid from path str*/
+ pkgid = __find_rpm_pkgid(path_str);
+ if (pkgid == NULL) {
+ _d_msg(DEBUG_ERR, "csc-info : fail to find pkgid\n");
+ return -1;
+ }
+ _d_msg(DEBUG_INFO, "csc-info : find pkgid=[%s] for installation\n", pkgid);
+
+ /*find xml name*/
+ token = strtok(path_str, delims);
+ while(token)
+ {
+ memset(xml_name, 0x00, sizeof(xml_name));
+ strncat(xml_name, token, strlen(token));
+ token = strtok(NULL, delims);
+ }
+ _d_msg(DEBUG_INFO, "csc-info : xml name = %s\n", xml_name);
+
+ /*copy xml to /opt/share/packages*/
+ snprintf(dest_file, sizeof(dest_file), "%s/%s", OPT_SHARE_PACKAGES, xml_name);
+ ret = __copy_file(src_file, dest_file);
+ if (ret != 0) {
+ _d_msg(DEBUG_ERR, "csc-info : xml copy fail(%d)\n", ret);
+ } else {
+ _d_msg(DEBUG_ERR, "csc-info : xml copy success to [%s] \n", dest_file);
+ }
+
+ /*remove old pkg info*/
+ ret = pkgmgr_parser_parse_manifest_for_uninstallation(pkgid, NULL);
+ if (ret < 0) {
+ _d_msg(DEBUG_INFO, "csc-info : fail remove old pkg info\n");
+ } else {
+ _d_msg(DEBUG_INFO, "csc-info : success remove old pkg info\n");
+ }
+
+ /*insert new pkg info*/
+ memset(argv, 0x00, sizeof(argv));
+ snprintf(argv, sizeof(argv), "%s/%s", OPT_SHARE_PACKAGES, xml_name);
+ ret = __ri_init_csc_xml(argv, remove_str);
+ if (ret < 0) {
+ _d_msg(DEBUG_INFO, "csc-info : fail insert db\n");
+ } else {
+ _d_msg(DEBUG_INFO, "csc-info : success xml name = %s\n", xml_name);
+ }
+
+ free(pkgid);
+
+ return 0;
+}
+
+static int __ri_uninstall_csc(char *pkgid)
+{
+ /*remove old pkg info*/
+ int ret = pkgmgr_parser_parse_manifest_for_uninstallation(pkgid, NULL);
+ if (ret < 0) {
+ _d_msg(DEBUG_INFO, "csc-info : fail remove old pkg info\n");
+ } else {
+ _d_msg(DEBUG_INFO, "csc-info : success remove old pkg info\n");
+ }
+
+ return 0;
+}
+
+static int __child_element(xmlTextReaderPtr reader, int depth)
+{
+ int ret = xmlTextReaderRead(reader);
+ int cur = xmlTextReaderDepth(reader);
+ while (ret == 1) {
+
+ switch (xmlTextReaderNodeType(reader)) {
+ case XML_READER_TYPE_ELEMENT:
+ if (cur == depth + 1)
+ return 1;
+ break;
+ case XML_READER_TYPE_TEXT:
+ /*text is handled by each function separately*/
+ if (cur == depth + 1)
+ return 0;
+ break;
+ case XML_READER_TYPE_END_ELEMENT:
+ if (cur == depth)
+ return 0;
+ break;
+ default:
+ if (cur <= depth)
+ return 0;
+ break;
+ }
+ ret = xmlTextReaderRead(reader);
+ cur = xmlTextReaderDepth(reader);
+ }
+ return ret;
+}
+
+static int __get_size_from_xml(const char *manifest, int *size)
+{
+ const char *val = NULL;
+ const xmlChar *node;
+ xmlTextReaderPtr reader;
+
+ if(manifest == NULL) {
+ _d_msg(DEBUG_ERR, "Input argument is NULL\n");
+ return PMINFO_R_ERROR;
+ }
+
+ if(size == NULL) {
+ _d_msg(DEBUG_ERR, "Argument supplied to hold return value is NULL\n");
+ return PMINFO_R_ERROR;
+ }
+
+ xmlInitParser();
+ reader = xmlReaderForFile(manifest, NULL, 0);
+
+ if (reader){
+ if (__child_element(reader, -1)) {
+ node = xmlTextReaderConstName(reader);
+ if (!node) {
+ _d_msg(DEBUG_ERR, "xmlTextReaderConstName value is NULL\n");
+ xmlFreeTextReader(reader);
+ xmlCleanupParser();
+ return PMINFO_R_ERROR;
+ }
+
+ if (!strcmp(ASC_CHAR(node), "manifest")) {
+ if (xmlTextReaderGetAttribute(reader, XML_CHAR("size")))
+ val = ASC_CHAR(xmlTextReaderGetAttribute(reader, XML_CHAR("size")));
+
+ if (val) {
+ *size = atoi(val);
+ } else {
+ *size = 0;
+ _d_msg(DEBUG_ERR, "package size is not specified\n");
+ xmlFreeTextReader(reader);
+ xmlCleanupParser();
+ return PMINFO_R_ERROR;
+ }
+ } else {
+ _d_msg(DEBUG_ERR, "Unable to create xml reader\n");
+ xmlFreeTextReader(reader);
+ xmlCleanupParser();
+ return PMINFO_R_ERROR;
+ }
+ }
+ } else {
+ _d_msg(DEBUG_ERR, "xmlReaderForFile value is NULL\n");
+ xmlCleanupParser();
+ return PMINFO_R_ERROR;
+ }
+
+ xmlFreeTextReader(reader);
+ xmlCleanupParser();
+
+ return PMINFO_R_OK;
+}
+
+static int __get_location_from_xml(const char *manifest, pkgmgrinfo_install_location *location)
+{
+ const char *val = NULL;
+ const xmlChar *node;
+ xmlTextReaderPtr reader;
+
+ if(manifest == NULL) {
+ _d_msg(DEBUG_ERR, "Input argument is NULL\n");
+ return PMINFO_R_ERROR;
+ }
+
+ if(location == NULL) {
+ _d_msg(DEBUG_ERR, "Argument supplied to hold return value is NULL\n");
+ return PMINFO_R_ERROR;
+ }
+
+ xmlInitParser();
+ reader = xmlReaderForFile(manifest, NULL, 0);
+
+ if (reader){
+ if ( __child_element(reader, -1)) {
+ node = xmlTextReaderConstName(reader);
+ if (!node) {
+ _d_msg(DEBUG_ERR, "xmlTextReaderConstName value is NULL\n");
+ xmlFreeTextReader(reader);
+ xmlCleanupParser();
+ return PMINFO_R_ERROR;
+ }
+
+ if (!strcmp(ASC_CHAR(node), "manifest")) {
+ if (xmlTextReaderGetAttribute(reader, XML_CHAR("install-location")))
+ val = ASC_CHAR(xmlTextReaderGetAttribute(reader, XML_CHAR("install-location")));
+
+ if (val) {
+ if (strcmp(val, "internal-only") == 0)
+ *location = PMINFO_INSTALL_LOCATION_INTERNAL_ONLY;
+ else if (strcmp(val, "prefer-external") == 0)
+ *location = PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL;
+ else
+ *location = PMINFO_INSTALL_LOCATION_AUTO;
+ }
+ } else {
+ _d_msg(DEBUG_ERR, "Unable to create xml reader\n");
+ xmlFreeTextReader(reader);
+ xmlCleanupParser();
+ return PMINFO_R_ERROR;
+ }
+ }
+ } else {
+ _d_msg(DEBUG_ERR, "xmlReaderForFile value is NULL\n");
+ xmlCleanupParser();
+ return PMINFO_R_ERROR;
+ }
+
+ xmlFreeTextReader(reader);
+ xmlCleanupParser();
+
+ return PMINFO_R_OK;
+}
+
+static char * __get_pkg_path(const char *pkg_path, const char *pkgid)
+{
+ int ret = 0;
+ char buff[BUF_SIZE] = {'\0'};
+ char *real_path = NULL;
+
+ snprintf(buff, BUF_SIZE, "%s/%s", pkg_path, pkgid);
+ do {
+ if (__is_dir(buff)) break;
+ memset(buff, '\0', BUF_SIZE);
+ snprintf(buff, BUF_SIZE, "/usr/apps/%s", pkgid);
+ if (__is_dir(buff)) break;
+ memset(buff, '\0', BUF_SIZE);
+ snprintf(buff, BUF_SIZE, "/opt/apps/%s", pkgid);
+ if (__is_dir(buff)) break;
+ memset(buff, '\0', BUF_SIZE);
+ snprintf(buff, BUF_SIZE, "/opt/usr/apps/%s", pkgid);
+ if (__is_dir(buff)) break;
+ } while (0);
+
+ ret = chdir(buff);
+ if (ret != 0) {
+ _d_msg(DEBUG_ERR, "chdir() failed [%s]\n", strerror(errno));
+ return NULL;
+ }
+
+ real_path = (char *)malloc(strlen(buff) + 1);
+ if (real_path == NULL) {
+ _d_msg(DEBUG_ERR, "Malloc failed!\n");
+ return NULL;
+ }
+ memset(real_path, '\0', strlen(buff) + 1);
+ memcpy(real_path, buff, strlen(buff));
+
+ return real_path;
+}
+
+void _ri_register_cert(const char *pkgid)
+{
+ int error = 0;
+ pkgmgrinfo_instcertinfo_h handle = NULL;
+ int i = 0;
+ /* create Handle*/
+ error = pkgmgrinfo_create_certinfo_set_handle(&handle);
+ if (error != 0) {
+ _d_msg(DEBUG_ERR, "Cert handle creation failed. Err:%d", error);
+ __ri_free_cert_chain();
+ return;
+ }
+
+ if (list[SIG_AUTH].cert_value == NULL) {
+ _d_msg(DEBUG_ERR, "pkgid[%s] dont have SIG_AUTH.cert_value ", pkgid);
+ goto err;
+ }
+
+ for (i = 0; i < MAX_CERT_NUM; i++) {
+
+ if (list[i].cert_value) {
+ error = pkgmgrinfo_set_cert_value(handle, list[i].cert_type, list[i].cert_value);
+ if (error != 0) {
+ _d_msg(DEBUG_ERR, "pkgmgrinfo_set_cert_value failed. cert type:%d. Err:%d", list[i].cert_type, error);
+ goto err;
+ }
+ }
+ }
+ /* Save the certificates in cert DB*/
+ error = pkgmgrinfo_save_certinfo(pkgid, handle);
+ if (error != 0) {
+ _d_msg(DEBUG_ERR, "pkgmgrinfo_save_certinfo failed. Err:%d", error);
+ goto err;
+ }
+err:
+ if (handle)
+ pkgmgrinfo_destroy_certinfo_set_handle(handle);
+ __ri_free_cert_chain();
+}
+
+void _ri_unregister_cert(const char *pkgid)
+{
+ int error = 0;
+ /* Delete the certifictes from cert DB*/
+ error = pkgmgrinfo_delete_certinfo(pkgid);
+ if (error != 0) {
+ _d_msg(DEBUG_ERR, "pkgmgrinfo_delete_certinfo failed. Err:%d", error);
+ return;
+ }
+}
+
+
+int _ri_verify_sig_and_cert(const char *sigfile)
+{
+ char certval[MAX_BUFF_LEN] = { '\0'};
+ int err = 0;
+ int validity = 0;
+ int i = 0;
+ int j= 0;
+ int ret = RPM_INSTALLER_SUCCESS;
+ char *crt = NULL;
+ signature_x *signx = NULL;
+ struct keyinfo_x *keyinfo = NULL;
+ struct x509data_x *x509data = NULL;
+ CERT_CONTEXT *ctx = NULL;
+ int sigtype = 0;
+
+ ctx = cert_svc_cert_context_init();
+ if (ctx == NULL) {
+ _d_msg(DEBUG_ERR, "cert_svc_cert_context_init() failed");
+ return RPM_INSTALLER_ERR_INTERNAL;
+ }
+ if (strstr(sigfile, AUTHOR_SIGNATURE_XML))
+ sigtype = SIG_AUTH;
+ else if (strstr(sigfile, SIGNATURE1_XML))
+ sigtype = SIG_DIST1;
+ else if (strstr(sigfile, SIGNATURE2_XML))
+ sigtype = SIG_DIST2;
+ else {
+ _d_msg(DEBUG_ERR, "Unsupported Signature type\n");
+ cert_svc_cert_context_final(ctx);
+ return RPM_INSTALLER_ERR_INTERNAL;
+ }
+ signx = _ri_process_signature_xml(sigfile);
+ if (signx == NULL) {
+ _d_msg(DEBUG_ERR, "Parsing %s failed", sigfile);
+ ret = RPM_INSTALLER_ERR_INTERNAL;
+ goto end;
+ }
+ keyinfo = signx->keyinfo;
+ if ((keyinfo == NULL) || (keyinfo->x509data == NULL) || (keyinfo->x509data->x509certificate == NULL)) {
+ _d_msg(DEBUG_ERR, "Certificates missing in %s", sigfile);
+ ret = RPM_INSTALLER_ERR_CERT_INVALID;
+ goto end;
+ }
+ x509data = keyinfo->x509data;
+ x509certificate_x *cert = x509data->x509certificate;
+ /*First cert is Signer certificate*/
+ if (cert->text != NULL) {
+ for (i = 0; i <= (int)strlen(cert->text); i++) {
+ if (cert->text[i] != '\n') {
+ certval[j++] = cert->text[i];
+ }
+ }
+ certval[j] = '\0';
+ _d_msg(DEBUG_INFO, " strlen[%d] cert_svc_load_buf_to_context() load %s", strlen(certval), certval);
+ err = cert_svc_load_buf_to_context(ctx, (unsigned char*)certval);
+ if (err != 0) {
+ _d_msg(DEBUG_ERR, "cert_svc_load_buf_to_context() failed. cert:%s err:%d", certval, err);
+ ret = RPM_INSTALLER_ERR_INTERNAL;
+ goto end;
+ }
+ err = __ri_create_cert_chain(sigtype, SIG_SIGNER, certval);
+ if (err) {
+ _d_msg(DEBUG_ERR, "Failed to push cert info in list\n");
+ __ri_free_cert_chain();
+ ret = RPM_INSTALLER_ERR_INTERNAL;
+ goto end;
+ }
+ }
+ /*Second cert is Intermediate certificate*/
+ cert = cert->next;
+ if (cert->text != NULL) {
+ memset(certval, 0x00, MAX_BUFF_LEN);
+ j = 0;
+ for (i = 0; i <= (int)strlen(cert->text); i++) {
+ if (cert->text[i] != '\n') {
+ certval[j++] = cert->text[i];
+ }
+ }
+ certval[j] = '\0';
+ _d_msg(DEBUG_INFO, " strlen[%d] cert_svc_push_file_into_context() load %s", strlen(certval), certval);
+ if (cert->text != NULL) {
+ err = cert_svc_push_buf_into_context(ctx, (unsigned char*)certval);
+ if (err != 0) {
+ _d_msg(DEBUG_ERR, "cert_svc_push_file_into_context() failed. cert:%s err:%d", certval, err);
+ ret = RPM_INSTALLER_ERR_INTERNAL;
+ goto end;
+ }
+ }
+ err = __ri_create_cert_chain(sigtype, SIG_INTERMEDIATE, certval);
+ if (err) {
+ _d_msg(DEBUG_ERR, "Failed to push cert info in list\n");
+ __ri_free_cert_chain();
+ ret = RPM_INSTALLER_ERR_INTERNAL;
+ goto end;
+ }
+ } else {
+ _d_msg(DEBUG_ERR, "Invalid CertChain");
+ ret = RPM_INSTALLER_ERR_CERT_INVALID;
+ goto end;
+ }
+ err = cert_svc_verify_certificate(ctx, &validity);
+ if (err != 0) {
+ _d_msg(DEBUG_ERR, "cert_svc_verify_certificate() failed");
+ ret = RPM_INSTALLER_ERR_INTERNAL;
+ goto end;
+ }
+ _d_msg(DEBUG_INFO, "Certificate verification completed. [%d]", validity);
+ if (validity == 0) {
+ _d_msg(DEBUG_ERR, "Certificate Invalid/Expired");
+ ret = RPM_INSTALLER_ERR_CERTCHAIN_VERIFICATION_FAILED;
+ goto end;
+ }
+ /*verify signature*/
+ /*For reference validation, we should be in TEMP_DIR/usr/apps/<pkgid>*/
+ if (ctx->fileNames && ctx->fileNames->filename) {
+ _d_msg(DEBUG_INFO, "Root CA cert is: %s\n", ctx->fileNames->filename);
+ err = __ri_xmlsec_verify_signature(sigfile, ctx->fileNames->filename);
+ if (err < 0) {
+ _d_msg(DEBUG_ERR, "signature validation failed\n");
+ ret = RPM_INSTALLER_ERR_SIG_VERIFICATION_FAILED;
+ goto end;
+ }
+ crt = __ri_get_cert_from_file(ctx->fileNames->filename);
+ err = __ri_create_cert_chain(sigtype, SIG_ROOT, crt);
+ if (err) {
+ _d_msg(DEBUG_ERR, "Failed to push cert info in list\n");
+ __ri_free_cert_chain();
+ ret = RPM_INSTALLER_ERR_INTERNAL;
+ goto end;
+ }
+ } else {
+ _d_msg(DEBUG_ERR, "No Root CA certificate found. Signature validation failed");
+ ret = RPM_INSTALLER_ERR_ROOT_CERT_NOT_FOUND;
+ goto end;
+ }
+ ret = 0;
+end:
+ cert_svc_cert_context_final(ctx);
+ ctx = NULL;
+ _ri_free_signature_xml(signx);
+ signx = NULL;
+ return ret;
+}
+
+static int _ri_verify_signatures(const char *root_path, const char *pkgid)
+{
+ int ret = 0;
+ char buff[BUF_SIZE] = {'\0'};
+ char *pkg_path = NULL;
+
+ /*check for signature and certificate*/
+ if (sig_enable) {
+ pkg_path = __get_pkg_path(root_path, pkgid);
+ if (pkg_path == NULL) {
+ return 0;
+ }
+
+ _d_msg(DEBUG_ERR, "Switched to %s\n", pkg_path);
+
+ /*signature2.xml is optional*/
+ snprintf(buff, BUF_SIZE, "%s/signature2.xml", pkg_path);
+ if (access(buff, F_OK) == 0) {
+ _d_msg(DEBUG_INFO, "signature2.xml found in %s\n", pkg_path);
+ ret = _ri_verify_sig_and_cert(buff);
+ if (ret) {
+ _d_msg(DEBUG_ERR, "Failed to verify [%s]\n", buff);
+ ret = -1;
+ goto end;
+ }
+ _d_msg(DEBUG_INFO, "Successfully verified [%s]\n", buff);
+ }
+ memset(buff, '\0', BUF_SIZE);
+
+ /*signature1.xml is mandatory*/
+ snprintf(buff, BUF_SIZE, "%s/signature1.xml", pkg_path);
+ if (access(buff, F_OK) == 0) {
+ _d_msg(DEBUG_INFO, "signature1.xml found in %s\n", pkg_path);
+ ret = _ri_verify_sig_and_cert(buff);
+ if (ret) {
+ _d_msg(DEBUG_ERR, "Failed to verify [%s]\n", buff);
+ ret = -1;
+ goto end;
+ }
+ _d_msg(DEBUG_INFO, "Successfully verified [%s]\n", buff);
+ }
+ memset(buff, '\0', BUF_SIZE);
+
+ /*author-signature.xml is mandatory*/
+ snprintf(buff, BUF_SIZE, "%s/author-signature.xml", pkg_path);
+ if (access(buff, F_OK) == 0) {
+ _d_msg(DEBUG_INFO, "author-signature.xml found in %s\n", pkg_path);
+ ret = _ri_verify_sig_and_cert(buff);
+ if (ret) {
+ _d_msg(DEBUG_ERR, "Failed to verify [%s]\n", buff);
+ ret = -1;
+ goto end;
+ }
+ _d_msg(DEBUG_INFO, "Successfully verified [%s]\n", buff);
+ }
+ memset(buff, '\0', BUF_SIZE);
+ ret = 0;
+ }
+
+end :
+ free(pkg_path);
+ return ret;
+}
+
+void _ri_apply_smack(char *pkgname, int flag)
+{
+ __rpm_apply_shared_privileges(pkgname, flag);
+}
+
+int _ri_apply_perm(char *pkgid)
+{
+ int ret = -1;
+ pkgmgrinfo_pkginfo_h handle = NULL;
+
+ ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle);
+ if (ret != PMINFO_R_OK)
+ return -1;
+
+ ret = pkgmgrinfo_pkginfo_foreach_privilege(handle, __privilege_func, (void *)pkgid);
+ if (ret != PMINFO_R_OK) {
+ _d_msg(DEBUG_ERR, "pkgmgrinfo_pkginfo_get_pkgid failed\n");
+ pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
+ return -1;
+ }
+ pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
+
+ return 0;
+}
+
+static int __ri_install_fota_for_rw(char *pkgid)
+{
+ int ret = 0;
+ int home_dir = 1;
+ char buff[BUF_SIZE] = {'\0'};
+
+ _d_msg(DEBUG_INFO, "fota-info : pkgid[%s] start installation\n", pkgid);
+
+ /*unzip pkg path from factoryrest data*/
+ snprintf(buff, BUF_SIZE, "opt/usr/apps/%s/*", pkgid);
+ const char *pkg_argv[] = { "/usr/bin/unzip", "-oX", OPT_ZIP_FILE, buff, "-d", "/", NULL };
+ ret = __ri_xsystem(pkg_argv);
+ if (ret != 0) {
+ _d_msg(DEBUG_ERR, "fota-info : unzip root path[%s] is fail .\n", buff);
+ return ret;
+ }
+
+ _d_msg(DEBUG_INFO, "fota-info : unzip root path[%s] is success\n", buff);
+
+ /*unzip manifest from factoryrest data*/
+ memset(buff, '\0', BUF_SIZE);
+ snprintf(buff, BUF_SIZE, "opt/share/packages/%s.xml", pkgid);
+
+ const char *xml_argv[] = { "/usr/bin/unzip", "-oX", OPT_ZIP_FILE, buff, "-d", "/", NULL };
+ ret = __ri_xsystem(xml_argv);
+ if (ret != 0) {
+ _d_msg(DEBUG_ERR, "fota-info : xml_argv fail for pkgid[%s] .\n", pkgid);
+ return ret;
+ }
+
+ _d_msg(DEBUG_INFO, "fota-info : xml_argv is success\n", pkgid);
+
+ /*get updated manifest path*/
+ memset(buff, '\0', BUF_SIZE);
+ snprintf(buff, BUF_SIZE, "%s/%s.xml", OPT_SHARE_PACKAGES, pkgid);
+ _d_msg(DEBUG_ERR, "Manifest name is %s\n", buff);
+
+ /*apply smack for manifest*/
+ _ri_privilege_change_smack_label(buff, pkgid, 0);/*0 is SMACK_LABEL_ACCESS*/
+
+ /*register manifest*/
+ char* fota_tags[3] = {NULL, };
+ fota_tags[0] = "removable=true";
+ fota_tags[1] = "preload=true";
+ fota_tags[2] = NULL;
+
+ ret = pkgmgr_parser_parse_manifest_for_installation(buff, fota_tags);
+ if (ret < 0) {
+ _d_msg(DEBUG_ERR, "Parsing Manifest Failed\n");
+ ret = -1;
+ goto err;
+ } else {
+ _d_msg(DEBUG_INFO, "Parsing Manifest Success\n");
+ }
+
+ /*apply smack for pkg root path*/
+ memset(buff, '\0', BUF_SIZE);
+ snprintf(buff, BUF_SIZE, "%s/%s", OPT_USR_APPS, pkgid);
+ _ri_privilege_setup_path(pkgid, buff, PERM_APP_PATH_ANY_LABEL, pkgid);
+
+ /*apply smack for defined directory*/
+ __rpm_apply_shared_privileges(pkgid, home_dir);
+
+ /*apply privilege*/
+ ret = _ri_apply_perm(pkgid);
+ if (ret != 0) {
+ _d_msg(DEBUG_ERR, "apply perm failed with err(%d)\n", ret);
+ } else {
+ _d_msg(DEBUG_INFO, "apply perm success\n");
+ }
+
+ /*Register cert info*/
+ _ri_register_cert(pkgid);
+
+err:
+
+ return ret;
+}
+
+static int __ri_upgrade_fota_for_rw(char *pkgid)
+{
+ int ret = 0;
+ int home_dir = 1;
+ char buff[BUF_SIZE] = {'\0'};
+
+ _d_msg(DEBUG_INFO, "fota-info : pkgid[%s] start upgrade\n", pkgid);
+
+ /*unzip pkg dir from factoryrest data*/
+ snprintf(buff, BUF_SIZE, "opt/usr/apps/%s/*", pkgid);
+ const char *pkg_argv[] = { "/usr/bin/unzip", "-oX", OPT_ZIP_FILE, buff, "-d", "/", NULL };
+ ret = __ri_xsystem(pkg_argv);
+ if (ret != 0) {
+ _d_msg(DEBUG_ERR, "fota-info : unzip root path[%s] is fail .\n", buff);
+ return ret;
+ }
+
+ _d_msg(DEBUG_INFO, "fota-info : unzip root path[%s] is success\n", buff);
+
+ /*unzip manifest from factoryrest data*/
+ memset(buff, '\0', BUF_SIZE);
+ snprintf(buff, BUF_SIZE, "opt/share/packages/%s.xml", pkgid);
+ const char *xml_argv[] = { "/usr/bin/unzip", "-oX", OPT_ZIP_FILE, buff, "-d", "/", NULL };
+ ret = __ri_xsystem(xml_argv);
+ if (ret != 0) {
+ _d_msg(DEBUG_ERR, "fota-info : unzip manifest[%s] is fail .\n", buff);
+ return ret;
+ }
+
+ _d_msg(DEBUG_INFO, "fota-info : unzip manifest[%s] is success\n", buff);
+
+ /*get updated manifest path*/
+ memset(buff, '\0', BUF_SIZE);
+ snprintf(buff, BUF_SIZE, "%s/%s.xml", OPT_SHARE_PACKAGES, pkgid);
+ _d_msg(DEBUG_ERR, "Manifest name is %s\n", buff);
+
+ /*apply smack for manifest*/
+ _ri_privilege_change_smack_label(buff, pkgid, 0);/*0 is SMACK_LABEL_ACCESS*/
+
+ /*register manifest*/
+ ret = pkgmgr_parser_parse_manifest_for_upgrade(buff, NULL);
+ if (ret < 0) {
+ _d_msg(DEBUG_ERR, "Parsing Manifest Failed\n");
+ ret = -1;
+ goto err;
+ } else {
+ _d_msg(DEBUG_INFO, "Parsing Manifest Success\n");
+ }
+
+ /*apply smack for pkg root path*/
+ memset(buff, '\0', BUF_SIZE);
+ snprintf(buff, BUF_SIZE, "%s/%s", OPT_USR_APPS, pkgid);
+ _ri_privilege_setup_path(pkgid, buff, PERM_APP_PATH_ANY_LABEL, pkgid);
+
+ /*apply smack for defined directory*/
+ __rpm_apply_shared_privileges(pkgid, home_dir);
+
+ /*apply privilege*/
+ ret = _ri_apply_perm(pkgid);
+ if (ret != 0) {
+ _d_msg(DEBUG_ERR, "apply perm failed with err(%d)\n", ret);
+ } else {
+ _d_msg(DEBUG_INFO, "apply perm success\n");
+ }
+
+ /*Register new cert info*/
+ _ri_unregister_cert(pkgid);
+ _ri_register_cert(pkgid);
+
+err:
+ return ret;
+}
+
+static int __ri_uninstall_fota_for_rw(char *pkgid)
+{
+ int ret = 0;
+ char buff[BUF_SIZE] = {'\0'};
+
+ _d_msg(DEBUG_INFO, "fota-info : pkgid[%s] start uninstall\n", pkgid);
+
+ /*del root path dir*/
+ snprintf(buff, BUF_SIZE, "%s/%s", OPT_USR_APPS, pkgid);
+
+ if (__is_dir(buff)) {
+ __rpm_delete_dir(buff);
+ }
+
+ /*del manifest*/
+ memset(buff, '\0', BUF_SIZE);
+ snprintf(buff, BUF_SIZE, "%s/%s.xml", OPT_SHARE_PACKAGES, pkgid);
+ (void)remove(buff);
+
+ /*del db info*/
+ ret = pkgmgr_parser_parse_manifest_for_uninstallation(pkgid, NULL);
+ if (ret < 0) {
+ _d_msg(DEBUG_ERR, "Parsing Manifest Failed\n");
+ }
+
+ /*execute privilege APIs*/
+ _ri_privilege_revoke_permissions(pkgid);
+ _ri_privilege_unregister_package(pkgid);
+
+ /*Unregister cert info*/
+ _ri_unregister_cert(pkgid);
+
+ return 0;
+}
+
+/**
+ * callback for the pkgmgrinfo_appinfo_get_list used in _rpm_uninstall_pkg()
+ */
+static int __ri_check_running_app(const pkgmgrinfo_appinfo_h handle, void *user_data)
+{
+ int ret = 0;
+ bool isRunning = 0;
+ char *appid = NULL;
+ app_context_h appCtx = NULL;
+
+ ret = pkgmgrinfo_appinfo_get_appid(handle, &appid);
+ if (ret < 0) {
+ _d_msg(DEBUG_ERR, "Failed to execute pkgmgrinfo_appinfo_get_appid[%d].\n", ret);
+ return ret;
+ }
+
+ ret = app_manager_is_running(appid, &isRunning);
+ if (ret < 0) {
+ _d_msg(DEBUG_ERR, "Failed to execute app_manager_is_running[%d].\n", ret);
+ return ret;
+ }
+ _d_msg(DEBUG_ERR, "app[%s] , running state[%d].\n", appid, isRunning);
+
+ if (isRunning) {
+ ret = app_manager_get_app_context(appid, &appCtx);
+ if (ret < 0) {
+ _d_msg(DEBUG_ERR, "Failed to execute app_manager_get_app_context[%d].\n", ret);
+ return ret;
+ }
+
+ ret = app_manager_terminate_app(appCtx);
+ if (ret < 0) {
+ _d_msg(DEBUG_ERR, "Failed to execute app_manager_terminate_app[%d].\n", ret);
+ app_context_destroy(appCtx);
+ return ret;
+ }
+
+ int i = 0;
+ for (i = 0; i < TERMINATE_RETRY_COUNT; i++) {
+ ret = app_manager_is_running(appid, &isRunning);
+ if (ret < 0) {
+ _d_msg(DEBUG_ERR, "Failed to execute app_manager_is_running[%d].\n", ret);
+ app_context_destroy(appCtx);
+ return ret;
+ }
+
+ if (!isRunning) {
+ _d_msg(DEBUG_INFO, "App(%s) is terminated.\n", appid);
+ break;
+ } else {
+ _d_msg(DEBUG_INFO, "App(%s) is not terminated yet. wait count = [%d].\n", appid, i);
+ usleep(100000);
+ }
+ }
+
+ ret = app_context_destroy(appCtx);
+ if (ret < 0) {
+ _d_msg(DEBUG_ERR, "Failed to execute app_context_destroy[%d].\n", ret);
+ return ret;
+ }
+ }
+
+ return ret;
+}
+
+static int __ri_change_dir(char *dirname)
+{
+ int ret = 0;
+
+ ret = mkdir(dirname, 0644);
+ if (ret < 0) {
+ if (access(dirname, F_OK) == 0) {
+ __rpm_delete_dir(dirname);
+ ret = mkdir(dirname, 0644);
+ if (ret < 0) {
+ _d_msg(DEBUG_ERR, "mkdir(%s) failed\n", dirname);
+ return -1;
+ }
+ } else {
+ _d_msg(DEBUG_ERR, "can not access[%s]\n", dirname);
+ return -1;
+ }
+ }
+
+ ret = chdir(dirname);
+ if (ret != 0) {
+ _d_msg(DEBUG_ERR, "chdir(%s) failed [%s]\n", dirname, strerror(errno));
+ return -1;
+ }
+ return 0;
+}
+
+int __ri_smack_reload(const char *pkgid, rpm_request_type request_type)
+{
+ int ret = 0;
+ char *op_type = NULL;
+
+ switch (request_type) {
+ case INSTALL_REQ:
+ op_type = strdup("install");
+ break;
+
+ case UPGRADE_REQ:
+ op_type = strdup("update");
+ break;
+
+ case UNINSTALL_REQ:
+ op_type = strdup("uninstall");
+ break;
+
+ default:
+ break;
+ }
+
+ if(op_type == NULL) {
+ _d_msg(DEBUG_ERR, "@Failed to reload smack. request_type not matched[pkgid=%s, op=%s]", pkgid, op_type);
+ return -1;
+ }
+
+ const char *smack_argv[] = { "/usr/bin/smack_reload.sh", op_type, pkgid, NULL };
+ ret = __ri_xsystem(smack_argv);
+ if (ret != 0) {
+ _d_msg(DEBUG_ERR, "@Failed to reload smack[pkgid=%s, op=%s].", pkgid, op_type);
+ } else {
+ _d_msg(DEBUG_INFO, "#success: smack reload[pkgid=%s, op=%s]", pkgid, op_type);
+ }
+ free(op_type);
+ return ret;
+}
+
+static void __ri_post_script(const char *pkgfilepath, const char *pkgid)
+{
+ char path_buf[BUF_SIZE] = {'\0'};
+
+ snprintf(path_buf, BUF_SIZE, "%s/rpm_post_tmp.sh", TEMP_DIR);
+
+ /*pkgfilepath=source rpm file, script_path=post script file from spec*/
+ const char *post_argv[] = { POST_SCRIPT, pkgfilepath, path_buf, NULL };
+ (void)__ri_xsystem(post_argv);
+
+ (void)chmod(path_buf, 0700);
+
+ /*run post script*/
+ const char *script_argv[] = {path_buf, NULL };
+ (void)__ri_xsystem(script_argv);
+
+ (void)remove(path_buf);
+
+ /*if data dir is on root path, apply owner ship as a app, smack label*/
+ memset(path_buf, '\0', BUF_SIZE);
+ snprintf(path_buf, BUF_SIZE, "%s/%s/data", OPT_USR_APPS, pkgid);
+ if (__is_dir(path_buf)) {
+ const char *chown_argv[] = { "/bin/chown", "-cR", "5000:5000", path_buf, NULL };
+ (void)__ri_xsystem(chown_argv);
+ _ri_privilege_change_smack_label(path_buf, pkgid, 0);
+ }
+
+ _d_msg(DEBUG_INFO, "#success: post_script");
+}
+
+static void __ri_remove_updated_dir(const char *pkgid)
+{
+ char path_buf[BUF_SIZE] = {'\0'};
+
+ /*check pkgid is null*/
+ if (pkgid == NULL) {
+ _d_msg(DEBUG_ERR, "@pkgid is null\n");
+ return;
+ }
+
+ /*remove bin dir*/
+ snprintf(path_buf, BUF_SIZE, "%s/%s/%s", OPT_USR_APPS, pkgid, BIN_DIR_STR);
+ if (__is_dir(path_buf)) {
+ _d_msg(DEBUG_ERR, "@pkgid[%s] need to clean dir[%s]\n", pkgid, path_buf);
+ __rpm_delete_dir(path_buf);
+ }
+
+ /*remove res dir*/
+ memset(path_buf, '\0', BUF_SIZE);
+ snprintf(path_buf, BUF_SIZE, "%s/%s/%s", OPT_USR_APPS, pkgid, RES_DIR_STR);
+ if (__is_dir(path_buf)) {
+ _d_msg(DEBUG_ERR, "@pkgid[%s] need to clean dir[%s]\n", pkgid, path_buf);
+ __rpm_delete_dir(path_buf);
+ }
+
+ /*remove shared/res dir*/
+ memset(path_buf, '\0', BUF_SIZE);
+ snprintf(path_buf, BUF_SIZE, "%s/%s/%s", OPT_USR_APPS, pkgid, SHARED_RES_DIR_STR);
+ if (__is_dir(path_buf)) {
+ _d_msg(DEBUG_ERR, "@pkgid[%s] need to clean dir[%s]\n", pkgid, path_buf);
+ __rpm_delete_dir(path_buf);
+ }
+}
+
+static int __metadata_func(const char *key, const char *value, void *user_data)
+{
+ int ret = 0;
+ bool isRunning = 0;
+
+ if (key == NULL) {
+ _d_msg(DEBUG_ERR, "key is null\n");
+ return -1;
+ }
+ if (value == NULL) {
+ _d_msg(DEBUG_ERR, "value is null\n");
+ return -1;
+ }
+ if (user_data == NULL) {
+ _d_msg(DEBUG_ERR, "user_data is null\n");
+ return -1;
+ }
+
+ if ((strcmp(key, "launch-on-attach") == 0) && (strcmp(value, "true") == 0)) {
+ _d_msg(DEBUG_ERR, "consumer[%s] : launch-on-attach is true \n", (char *)user_data);
+
+ ret = app_manager_is_running((char *)user_data, &isRunning);
+ if (ret < 0) {
+ _d_msg(DEBUG_ERR, "Failed to execute app_manager_is_running[%s].\n", (char *)user_data);
+ return ret;
+ }
+
+ if (isRunning) {
+ _d_msg(DEBUG_ERR, "consumer[%s] is already launched \n", (char *)user_data);
+ } else {
+ usleep(100 * 1000); /* 100ms sleep for infomation ready*/
+ ret = aul_launch_app((char *)user_data, NULL);
+ if (ret == AUL_R_ERROR) {
+ _d_msg(DEBUG_ERR, "consumer[%s] launch fail, sleep and retry launch_app\n", (char *)user_data);
+ usleep(100 * 1000); /* 100ms sleep for infomation ready*/
+ aul_launch_app((char *)user_data, NULL);
+ }
+ _d_msg(DEBUG_ERR, "consumer[%s] is launched !!!! \n", (char *)user_data);
+ }
+ }
+ return 0;
+}
+
+static int __ri_find_svcapp(const pkgmgrinfo_appinfo_h handle, void *user_data)
+{
+ int ret = 0;
+ char *appid = NULL;
+ char *component_type = NULL;
+
+ ret = pkgmgrinfo_appinfo_get_component_type(handle, &component_type);
+ if (ret != PMINFO_R_OK) {
+ _d_msg(DEBUG_ERR, "@Failed to get component_type\n");
+ return -1;
+ }
+
+ if (strcmp(component_type, "svcapp") == NULL) {
+ ret = pkgmgrinfo_appinfo_get_appid(handle, &appid);
+ if (ret != PMINFO_R_OK) {
+ _d_msg(DEBUG_ERR, "@Failed to get appid\n");
+ return -1;
+ }
+ _d_msg(DEBUG_ERR, "@find consumer[%s], check metadata for launch\n", appid);
+
+ ret = pkgmgrinfo_appinfo_foreach_metadata(handle, __metadata_func, (void *)appid);
+ if (ret != PMINFO_R_OK) {
+ _d_msg(DEBUG_ERR, "@Failed to get foreach_metadata\n");
+ return -1;
+ }
+ }
+
+ return 0;
+}
+
+static void __ri_launch_consumer(const char *pkgid)
+{
+ int ret = 0;
+ pkgmgrinfo_pkginfo_h pkghandle = NULL;
+
+ ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &pkghandle);
+ if (ret < 0) {
+ _d_msg(DEBUG_ERR, "@Failed to get pkginfo handle [%s]\n", pkgid);
+ return;
+ }
+
+ ret = pkgmgrinfo_appinfo_get_list(pkghandle, PM_UI_APP, __ri_find_svcapp, NULL);
+ if (ret < 0) {
+ _d_msg(DEBUG_ERR, "@Failed to get appinfo_get_list [%s]\n", pkgid);
+ return;
+ }
+ pkgmgrinfo_pkginfo_destroy_pkginfo(pkghandle);
+ if (ret < 0) {
+ _d_msg(DEBUG_ERR, "@Failed to get destroy_pkginfo [%s]\n", pkgid);
+ }
+}
+
+static int __ail_change_info(int op, const char *appid)
+{
+ void *lib_handle = NULL;
+ int (*ail_desktop_operation) (const char *);
+ char *aop = NULL;
+ int ret = 0;
+
+ if ((lib_handle = dlopen(LIBAIL_PATH, RTLD_LAZY)) == NULL) {
+ _d_msg(DEBUG_ERR, "dlopen is failed LIBAIL_PATH[%s]\n", LIBAIL_PATH);
+ goto END;
+ }
+
+
+ switch (op) {
+ case 0:
+ aop = "ail_desktop_add";
+ break;
+ case 1:
+ aop = "ail_desktop_update";
+ break;
+ case 2:
+ aop = "ail_desktop_remove";
+ break;
+ case 3:
+ aop = "ail_desktop_clean";
+ break;
+ case 4:
+ aop = "ail_desktop_fota";
+ break;
+ default:
+ goto END;
+ break;
+ }
+
+ if ((ail_desktop_operation =
+ dlsym(lib_handle, aop)) == NULL || dlerror() != NULL) {
+ _d_msg(DEBUG_ERR, "can not find symbol \n");
+
+ goto END;
+ }
+
+ ret = ail_desktop_operation(appid);
+
+END:
+ if (lib_handle)
+ dlclose(lib_handle);
+
+ return ret;
+}
+
+static int __ri_update_ail_info(const pkgmgrinfo_appinfo_h handle, void *user_data)
+{
+ int ret = 0;
+ char *appid = NULL;
+
+ ret = pkgmgrinfo_appinfo_get_appid(handle, &appid);
+ if (ret < 0) {
+ _d_msg(DEBUG_ERR, "Failed to execute pkgmgrinfo_appinfo_get_appid[%d].\n", ret);
+ return ret;
+ }
+
+ ret = __ail_change_info(AIL_INSTALL, appid);
+ if (ret < 0) {
+ _d_msg(DEBUG_ERR, "Failed to execute __ail_change_info[%s].\n", appid);
+ }
+
+ return ret;
+}
+
+int _rpm_install_pkg_with_dbpath(char *pkgfilepath, char *pkgid)
+{
+ int ret = 0;
+ char buff[BUF_SIZE] = {'\0'};
+ char manifest[BUF_SIZE] = { '\0'};
+ char srcpath[BUF_SIZE] = {'\0'};
+ pkgmgrinfo_install_location location = 1;
+ int size = -1;
+ char cwd[BUF_SIZE] = {'\0'};
+ int home_dir = 0;
+
+ /*send event for start*/
+ _ri_broadcast_status_notification(pkgid, "start", "install");
+
+ _d_msg(DEBUG_INFO, "[#]start : _rpm_install_pkg_with_dbpath\n");
+
+ /*getcwd*/
+ getcwd(cwd, BUF_SIZE);
+ if (cwd[0] == '\0') {
+ _d_msg(DEBUG_ERR, "@getcwd() failed.\n");
+ ret = RPM_INSTALLER_ERR_INTERNAL;
+ goto err;
+ }
+ _d_msg(DEBUG_INFO, "#Current working directory is %s\n", cwd);
+
+ /*change dir*/
+ ret = __ri_change_dir(TEMP_DIR);
+ if (ret == -1) {
+ _d_msg(DEBUG_ERR, "@change dir failed.\n");
+ ret = RPM_INSTALLER_ERR_INTERNAL;
+ goto err;
+ }
+ _d_msg(DEBUG_INFO, "#Switched to %s\n", TEMP_DIR);
+
+ /*run cpio script*/
+ const char *cpio_argv[] = { CPIO_SCRIPT, pkgfilepath, NULL };
+ ret = __ri_xsystem(cpio_argv);
+
+ /*get manifext.xml path*/
+ snprintf(manifest, BUF_SIZE, "%s/opt/share/packages/%s.xml", TEMP_DIR, pkgid);
+ _d_msg(DEBUG_INFO, "#Manifest name is %s\n", manifest);
+
+ if (access(manifest, F_OK)) {
+ _d_msg(DEBUG_INFO, "#There is no RW manifest.xml. check RO manifest.xml.\n");
+
+ memset(manifest, '\0', sizeof(manifest));
+ snprintf(manifest, BUF_SIZE, "%s/usr/share/packages/%s.xml", TEMP_DIR, pkgid);
+ _d_msg(DEBUG_INFO, "#Manifest name is %s\n", manifest);
+
+ if (access(manifest, F_OK)) {
+ _d_msg(DEBUG_ERR, "@Can not find manifest.xml in the pkg.\n");
+ ret = RPM_INSTALLER_ERR_NO_MANIFEST;
+ goto err;
+ } else {
+ home_dir = 0;
+ }
+
+ snprintf(srcpath, BUF_SIZE, "%s", manifest);
+ memset(manifest, '\0', sizeof(manifest));
+ snprintf(manifest, BUF_SIZE, "%s/%s.xml", MANIFEST_RW_DIRECTORY, pkgid);
+
+ const char *xml_update_argv[] = { CPIO_SCRIPT_UPDATE_XML, srcpath, manifest, NULL };
+ ret = __ri_xsystem(xml_update_argv);
+
+ } else {
+ home_dir = 1;
+ }
+ /*send event for install_percent*/
+ _ri_broadcast_status_notification(pkgid, "install_percent", "30");
+
+ /*check manifest.xml validation*/
+ ret = pkgmgr_parser_check_manifest_validation(manifest);
+ if(ret < 0) {
+ _d_msg(DEBUG_ERR, "@invalid manifest\n");
+ ret = RPM_INSTALLER_ERR_INVALID_MANIFEST;
+ goto err;
+ }
+
+ /*check for signature and certificate*/
+ _ri_verify_signatures(TEMP_DIR, pkgid);
+ if (ret < 0) {
+ _d_msg(DEBUG_ERR, "@signature and certificate failed(%s).\n", pkgid);
+ ret = RPM_INSTALLER_ERR_SIG_INVALID;
+ goto err;
+ }
+ _d_msg(DEBUG_INFO, "#_ri_verify_signatures success.\n");
+
+ /*chdir*/
+ ret = chdir(cwd);
+ if (ret != 0) {
+ _d_msg(DEBUG_ERR, "@chdir(%s) failed [%s]\n", cwd, strerror(errno));
+ ret = RPM_INSTALLER_ERR_INTERNAL;
+ goto err;
+ }
+
+ /*run script*/
+ if (home_dir == 0) {
+ const char *argv[] = { INSTALL_SCRIPT_WITH_DBPATH_RO, pkgfilepath, NULL };
+ ret = __ri_xsystem(argv);
+ } else {
+ const char *argv[] = { INSTALL_SCRIPT_WITH_DBPATH_RW, pkgfilepath, NULL };
+ ret = __ri_xsystem(argv);
+ }
+ if (ret != 0) {
+ _d_msg(DEBUG_ERR, "@install complete with error(%d)\n", ret);
+ goto err;
+ }
+ _d_msg(DEBUG_INFO, "#install script success.\n");
+
+ /*send event for install_percent*/
+ _ri_broadcast_status_notification(pkgid, "install_percent", "60");
+
+ /*if post is in rpm-spec, execute post as a script*/
+ //__ri_post_script(pkgfilepath, pkgid);
+
+ /*Parse the manifest to get install location and size. If installation fails, remove manifest info from DB*/
+ ret = pkgmgr_parser_parse_manifest_for_installation(manifest, NULL);
+ if (ret < 0) {
+ _d_msg(DEBUG_ERR, "@Parsing Manifest Failed\n");
+ ret = RPM_INSTALLER_ERR_INTERNAL;
+ goto err;
+ }
+ _d_msg(DEBUG_INFO, "#Parsing Manifest Success\n");
+
+ /*apply smack to shared dir*/
+ __rpm_apply_shared_privileges(pkgid, 1);
+
+ /*apply smack by privilege*/
+ ret = _ri_apply_perm(pkgid);
+ if (ret != 0) {
+ _d_msg(DEBUG_ERR, "@apply perm failed with err(%d)\n", ret);
+ }
+ _d_msg(DEBUG_INFO, "#apply perm success\n");
+
+ /*register cert info*/
+ _ri_register_cert(pkgid);
+
+ /*reload smack*/
+ ret = __ri_smack_reload(pkgid, INSTALL_REQ);
+ if (ret != 0) {
+ _d_msg(DEBUG_INFO, "__ri_smack_reload failed.\n");
+ }
+ /*send event for install_percent*/
+ _ri_broadcast_status_notification(pkgid, "install_percent", "100");
+
+err:
+ __rpm_delete_dir(TEMP_DIR);
+ __rpm_delete_dir(TEMP_DBPATH);
+
+ if (ret == 0) {
+ _d_msg(DEBUG_INFO, "[#]end : _rpm_install_pkg_with_dbpath\n");
+ _ri_broadcast_status_notification(pkgid, "end", "ok");
+ __ri_launch_consumer(pkgid);
+ } else {
+ _d_msg(DEBUG_ERR, "[@]end : _rpm_install_pkg_with_dbpath\n");
+ _ri_broadcast_status_notification(pkgid, "end", "fail");
+ }
+
+ return ret;
+}
+
+int _rpm_upgrade_pkg_with_dbpath(char *pkgfilepath, char *pkgid)
+{
+ int ret = 0;
+ char manifest[BUF_SIZE] = { '\0'};
+ char buff[BUF_SIZE] = { '\0' };
+ char srcpath[BUF_SIZE] = {'\0'};
+ pkgmgr_install_location location = 1;
+ int size = -1;
+ char cwd[BUF_SIZE] = {'\0'};
+ int home_dir = 0;
+ pkgmgrinfo_pkginfo_h pkghandle;
+
+ _ri_broadcast_status_notification(pkgid, "start", "update");
+
+ _d_msg(DEBUG_INFO, "[#]start : _rpm_upgrade_pkg_with_dbpath\n");
+
+ /*terminate running app*/
+ ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &pkghandle);
+ if (ret < 0) {
+ _d_msg(DEBUG_ERR, "@Failed to get pkginfo handle\n");
+ ret = RPM_INSTALLER_ERR_PKG_NOT_FOUND;
+ goto err;
+ }
+ pkgmgrinfo_appinfo_get_list(pkghandle, PM_UI_APP, __ri_check_running_app, NULL);
+ pkgmgrinfo_pkginfo_destroy_pkginfo(pkghandle);
+
+ /*getcwd*/
+ getcwd(cwd, BUF_SIZE);
+ if (cwd[0] == '\0') {
+ _d_msg(DEBUG_ERR, "@getcwd() failed.\n");
+ ret = RPM_INSTALLER_ERR_INTERNAL;
+ goto err;
+ }
+ _d_msg(DEBUG_INFO, "#Current working directory is %s.\n", cwd);
+
+ /*change dir*/
+ ret = __ri_change_dir(TEMP_DIR);
+ if (ret == -1) {
+ _d_msg(DEBUG_ERR, "@change dir failed.\n");
+ ret = RPM_INSTALLER_ERR_INTERNAL;
+ goto err;
+ }
+ _d_msg(DEBUG_INFO, "#Switched to %s\n", TEMP_DIR);
+
+ /*run cpio script*/
+ const char *cpio_argv[] = { CPIO_SCRIPT, pkgfilepath, NULL };
+ ret = __ri_xsystem(cpio_argv);
+
+ /*get manifext.xml path*/
+ snprintf(manifest, BUF_SIZE, "%s/opt/share/packages/%s.xml", TEMP_DIR, pkgid);
+ _d_msg(DEBUG_INFO, "#Manifest name is %s.\n", manifest);
+
+ if (access(manifest, F_OK)) {
+ _d_msg(DEBUG_INFO, "#There is no RW manifest.xml. check RO manifest.xml.\n");
+
+ memset(manifest, '\0', sizeof(manifest));
+ snprintf(manifest, BUF_SIZE, "%s/usr/share/packages/%s.xml", TEMP_DIR, pkgid);
+ _d_msg(DEBUG_INFO, "#Manifest name is %s.\n", manifest);
+
+ if (access(manifest, F_OK)) {
+ _d_msg(DEBUG_ERR, "@Can not find manifest.xml in the pkg.\n");
+ ret = RPM_INSTALLER_ERR_NO_MANIFEST;
+ goto err;
+ } else {
+ home_dir = 0;
+ }
+
+ snprintf(srcpath, BUF_SIZE, "%s", manifest);
+ memset(manifest, '\0', sizeof(manifest));
+ snprintf(manifest, BUF_SIZE, "%s/%s.xml", MANIFEST_RW_DIRECTORY, pkgid);
+
+ const char *xml_update_argv[] = { CPIO_SCRIPT_UPDATE_XML, srcpath, manifest, NULL };
+ ret = __ri_xsystem(xml_update_argv);
+
+ } else {
+ home_dir = 1;
+ }
+
+ /*send event for install_percent*/
+ _ri_broadcast_status_notification(pkgid, "install_percent", "30");
+
+ /*check manifest.xml validation*/
+ ret = pkgmgr_parser_check_manifest_validation(manifest);
+ if(ret < 0) {
+ _d_msg(DEBUG_ERR, "@invalid manifest\n");
+ ret = RPM_INSTALLER_ERR_INVALID_MANIFEST;
+ goto err;
+ }
+
+ /*check for signature and certificate*/
+ _ri_verify_signatures(TEMP_DIR, pkgid);
+ if (ret < 0) {
+ _d_msg(DEBUG_ERR, "@signature and certificate failed(%s).\n", pkgid);
+ ret = RPM_INSTALLER_ERR_SIG_INVALID;
+ goto err;
+ }
+ _d_msg(DEBUG_INFO, "#_ri_verify_signatures success.\n");
+
+ /*chdir*/
+ ret = chdir(cwd);
+ if (ret != 0) {
+ _d_msg(DEBUG_ERR, "@chdir(%s) failed(%s).\n", cwd, strerror(errno));
+ ret = RPM_INSTALLER_ERR_INTERNAL;
+ goto err;
+ }
+
+ /*remove dir for clean*/
+ __ri_remove_updated_dir(pkgid);
+
+ /*run script*/
+ if (home_dir == 0) {
+ const char *argv[] = { UPGRADE_SCRIPT_WITH_DBPATH_RO, pkgfilepath, NULL };
+ ret = __ri_xsystem(argv);
+ } else {
+ const char *argv[] = { UPGRADE_SCRIPT_WITH_DBPATH_RW, pkgfilepath, NULL };
+ ret = __ri_xsystem(argv);
+ }
+ if (ret != 0) {
+ _d_msg(DEBUG_ERR, "@upgrade complete with error(%d)\n", ret);
+ goto err;
+ }
+ _d_msg(DEBUG_INFO, "#upgrade script success.\n");
+
+ /*send event for install_percent*/
+ _ri_broadcast_status_notification(pkgid, "install_percent", "60");
+
+ /*if post is in rpm-spec, execute post as a script*/
+ //__ri_post_script(pkgfilepath, pkgid);
+
+ /*Parse the manifest to get install location and size. If fails, remove manifest info from DB.*/
+ ret = pkgmgr_parser_parse_manifest_for_upgrade(manifest, NULL);
+ if (ret < 0) {
+ _d_msg(DEBUG_ERR, "@Parsing manifest failed.\n");
+ ret = RPM_INSTALLER_ERR_INTERNAL;
+ goto err;
+ }
+ _d_msg(DEBUG_INFO, "#Parsing manifest success.\n");
+
+ /*apply smack to shared dir*/
+ __rpm_apply_shared_privileges(pkgid, 1);
+
+ /*apply smack by privilege*/
+ ret = _ri_apply_perm(pkgid);
+ if (ret != 0) {
+ _d_msg(DEBUG_ERR, "@apply perm failed with err(%d)\n", ret);
+ }
+ _d_msg(DEBUG_INFO, "#apply perm success.\n");
+
+ /*unregister cert info*/
+ _ri_unregister_cert(pkgid);
+
+ /*register cert info*/
+ _ri_register_cert(pkgid);
+
+ /*reload smack*/
+ ret = __ri_smack_reload(pkgid, UPGRADE_REQ);
+ if (ret != 0) {
+ _d_msg(DEBUG_INFO, "__ri_smack_reload failed.\n");
+ }
+
+ /*send event for install_percent*/
+ _ri_broadcast_status_notification(pkgid, "install_percent", "100");
+
+err:
+ __rpm_delete_dir(TEMP_DIR);
+ __rpm_delete_dir(TEMP_DBPATH);
+
+ if (ret == 0) {
+ _d_msg(DEBUG_INFO, "[#]end : _rpm_upgrade_pkg_with_dbpath\n");
+ _ri_broadcast_status_notification(pkgid, "end", "ok");
+ __ri_launch_consumer(pkgid);
+ } else {
+ _d_msg(DEBUG_ERR, "[@]end : _rpm_upgrade_pkg_with_dbpath\n");
+ _ri_broadcast_status_notification(pkgid, "end", "fail");
+ }
+
+ return ret;
+}
+
+int _rpm_uninstall_pkg_with_dbpath(char *pkgid, bool is_system)
+{
+ int ret = 0;
+ char buff[BUF_SIZE] = {'\0'};
+ pkgmgrinfo_pkginfo_h pkghandle = NULL;
+
+ if(pkgid == NULL) {
+ _d_msg(DEBUG_INFO, "pkgid is null\n");
+ return -1;
+ }
+
+ _d_msg(DEBUG_INFO, "[#]start : _rpm_uninstall_pkg_with_dbpath(%s)\n", pkgid);
+
+ /*send start event*/
+ if (is_system)
+ _ri_broadcast_status_notification(pkgid, "start", "update");
+ else
+ _ri_broadcast_status_notification(pkgid, "start", "uninstall");
+
+ /*terminate running app*/
+ ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &pkghandle);
+ if (ret < 0) {
+ _d_msg(DEBUG_ERR, "@Failed to get pkginfo handle\n");
+ ret = RPM_INSTALLER_ERR_PKG_NOT_FOUND;
+ goto end;
+ }
+ pkgmgrinfo_appinfo_get_list(pkghandle, PM_UI_APP, __ri_check_running_app, NULL);
+ pkgmgrinfo_pkginfo_destroy_pkginfo(pkghandle);
+
+ /*del root path dir*/
+ snprintf(buff, BUF_SIZE, "%s/%s", OPT_USR_APPS, pkgid);
+ if (__is_dir(buff)) {
+ __rpm_delete_dir(buff);
+ }
+
+ /*del manifest*/
+ memset(buff, '\0', BUF_SIZE);
+ snprintf(buff, BUF_SIZE, "%s/%s.xml", OPT_SHARE_PACKAGES, pkgid);
+ (void)remove(buff);
+
+ /*check system pkg, if pkg is system pkg, need to update xml on USR_SHARE_PACKAGES*/
+ if (is_system) {
+ memset(buff, '\0', BUF_SIZE);
+ snprintf(buff, BUF_SIZE, "%s/%s.xml", USR_SHARE_PACKAGES, pkgid);
+ ret = pkgmgr_parser_parse_manifest_for_upgrade(buff, NULL);
+ if (ret < 0) {
+ _d_msg(DEBUG_ERR, "@Parsing manifest failed.\n");
+ }
+ goto end;
+ } else {
+ /*del db info*/
+ ret = pkgmgr_parser_parse_manifest_for_uninstallation(pkgid, NULL);
+ if (ret < 0) {
+ _d_msg(DEBUG_ERR, "@Parsing Manifest Failed\n");
+ }
+ }
+
+ /*execute privilege APIs*/
+ _ri_privilege_revoke_permissions(pkgid);
+ _ri_privilege_unregister_package(pkgid);
+
+ /*Unregister cert info*/
+ _ri_unregister_cert(pkgid);
+
+ /*reload smack*/
+ ret = __ri_smack_reload(pkgid, UNINSTALL_REQ);
+ if (ret != 0) {
+ _d_msg(DEBUG_INFO, "__ri_smack_reload failed.\n");
+ }
+
+end:
+ if (ret != 0) {
+ _d_msg(DEBUG_ERR, "[@]end : _rpm_uninstall_pkg_with_dbpath\n");
+ _ri_broadcast_status_notification(pkgid, "end", "fail");
+ } else {
+ _d_msg(DEBUG_INFO, "[#]end : _rpm_uninstall_pkg_with_dbpath\n");
+ _ri_broadcast_status_notification(pkgid, "end", "ok");
+ }
+
+ return ret;
+}
+
+int _rpm_uninstall_pkg(char *pkgid)
+{
+ int ret = 0;
+ int err = 0;
+ bool is_update = 0;
+ bool is_system = 0;
+ bool is_removable = 0;
+ char buff[BUF_SIZE] = {'\0'};
+ pkgmgr_install_location location = 1;
+#ifdef APP2EXT_ENABLE
+ app2ext_handle *handle = NULL;
+#endif
+ char *manifest = NULL;
+ pkgmgrinfo_pkginfo_h pkghandle;
+ const char *argv[] = { UNINSTALL_SCRIPT, pkgid, NULL };
+
+ _d_msg(DEBUG_INFO, "start : _rpm_uninstall_pkg\n");
+
+ ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &pkghandle);
+ if (ret < 0) {
+ _d_msg(DEBUG_ERR, "Failed to get pkginfo handle\n");
+ return RPM_INSTALLER_ERR_PKG_NOT_FOUND;
+ }
+
+ ret = pkgmgrinfo_pkginfo_is_system(pkghandle, &is_system);
+ if (ret < 0) {
+ _d_msg(DEBUG_ERR, "pkgmgrinfo_pkginfo_is_system failed.\n");
+ return RPM_INSTALLER_ERR_INTERNAL;
+ }
+ if (is_system) {
+ ret = pkgmgrinfo_pkginfo_is_update(pkghandle, &is_update);
+ if (ret < 0) {
+ _d_msg(DEBUG_ERR, "pkgmgrinfo_pkginfo_is_system failed.\n");
+ return RPM_INSTALLER_ERR_INTERNAL;
+ }
+ if (is_update) {
+ pkgmgrinfo_pkginfo_destroy_pkginfo(pkghandle);
+ /*updated and system pkg need to "remove-update"*/
+ ret = _rpm_uninstall_pkg_with_dbpath(pkgid, 1);
+ if (ret < 0) {
+ _d_msg(DEBUG_ERR, "uninstall_pkg_with_dbpath for system, is_update fail\n");
+ }
+ return 0;
+ }
+ } else {
+ pkgmgrinfo_pkginfo_is_removable(pkghandle, &is_removable);
+ if (is_removable) {
+ /*non-system and can be removable, it should be deleted*/
+ pkgmgrinfo_pkginfo_destroy_pkginfo(pkghandle);
+ ret = _rpm_uninstall_pkg_with_dbpath(pkgid, 0);
+ if (ret < 0) {
+ _d_msg(DEBUG_ERR, "uninstall_pkg_with_dbpath for non-system, is_remove fail\n");
+ }
+ return 0;
+ }
+ }
+
+ _ri_broadcast_status_notification(pkgid, "start", "uninstall");
+
+#ifdef APP2EXT_ENABLE
+ ret = pkgmgrinfo_pkginfo_get_install_location(pkghandle, &location);
+ if (ret < 0) {
+ _d_msg(DEBUG_ERR, "Failed to get install location\n");
+ pkgmgr_pkginfo_destroy_pkginfo(pkghandle);
+ return RPM_INSTALLER_ERR_INTERNAL;
+ }
+
+ pkgmgrinfo_appinfo_get_list(pkghandle, PM_UI_APP, __ri_check_running_app, NULL);
+
+ pkgmgrinfo_pkginfo_destroy_pkginfo(pkghandle);
+ if (location == PM_INSTALL_LOCATION_PREFER_EXTERNAL) {
+ handle = app2ext_init(APP2EXT_SD_CARD);
+ if (handle == NULL) {
+ _d_msg(DEBUG_ERR, "app2ext init failed\n");
+ return RPM_INSTALLER_ERR_INTERNAL;
+ }
+ if ((&(handle->interface) != NULL) && (handle->interface.pre_uninstall != NULL) && (handle->interface.post_uninstall != NULL)){
+ ret = app2ext_get_app_location(pkgid);
+ if (ret == APP2EXT_INTERNAL_MEM){
+ _d_msg(DEBUG_ERR, "app2xt APP is not in MMC, go internal (%d)\n", ret);
+ }
+ else {
+ ret = handle->interface.pre_uninstall(pkgid);
+ if (ret == APP2EXT_ERROR_MMC_STATUS || ret == APP2EXT_SUCCESS ) {
+ _d_msg(DEBUG_ERR, "app2xt MMC is not here, go internal (%d)\n", ret);
+ }
+ else {
+ _d_msg(DEBUG_ERR, "app2xt pre uninstall API failed (%d)\n", ret);
+ handle->interface.post_uninstall(pkgid);
+ app2ext_deinit(handle);
+ return RPM_INSTALLER_ERR_INTERNAL;
+ }
+ }
+ }
+ }
+#endif
+
+#ifdef PRE_CHECK_FOR_MANIFEST
+ /*Manifest info should be removed first because after installation manifest
+ file is uninstalled. If uninstallation fails, we need to re-insert manifest info for consistency*/
+ manifest = pkgmgr_parser_get_manifest_file(pkgid);
+ if (manifest == NULL) {
+ _d_msg(DEBUG_ERR, "manifest name is NULL\n");
+ app2ext_deinit(handle);
+ return RPM_INSTALLER_ERR_NO_MANIFEST;
+ }
+ _d_msg(DEBUG_INFO, "manifest name is %s\n", manifest);
+ ret = pkgmgr_parser_parse_manifest_for_uninstallation(manifest, NULL);
+ if (ret < 0) {
+ _d_msg(DEBUG_ERR, "pkgmgr_parser_parse_manifest_for_uninstallation failed.\n");
+ }
+
+#endif
+
+ ret = __rpm_xsystem(argv);
+ if (ret != 0) {
+ _d_msg(DEBUG_ERR, "uninstall failed with error(%d)\n", ret);
+ #ifdef PRE_CHECK_FOR_MANIFEST
+ err = pkgmgr_parser_parse_manifest_for_installation(manifest, NULL);
+ if (err < 0) {
+ _d_msg(DEBUG_ERR, "Parsing Manifest Failed\n");
+ }
+ if (manifest) {
+ free(manifest);
+ manifest = NULL;
+ }
+ #endif
+ #ifdef APP2EXT_ENABLE
+ if ((handle != NULL) && (handle->interface.post_uninstall != NULL)){
+ handle->interface.post_uninstall(pkgid);
+ app2ext_deinit(handle);
+ }
+ #endif
+ return ret;
+ }
+
+#ifdef APP2EXT_ENABLE
+ if ((handle != NULL) && (handle->interface.post_uninstall != NULL)){
+ handle->interface.post_uninstall(pkgid);
+ app2ext_deinit(handle);
+ }
+#endif
+
+#ifdef PRE_CHECK_FOR_MANIFEST
+ if (manifest) {
+ free(manifest);
+ manifest = NULL;
+ }
+#endif
+ /* Uninstallation Success. Remove the installation time key from vconf*/
+ snprintf(buff, BUF_SIZE, "db/app-info/%s/installed-time", pkgid);
+ err = vconf_unset(buff);
+ if (err) {
+ _d_msg(DEBUG_ERR, "unset installation time failed\n");
+ }
+ /*execute privilege APIs*/
+ _ri_privilege_revoke_permissions(pkgid);
+ _ri_privilege_unregister_package(pkgid);
+ /*Unregister cert info*/
+ _ri_unregister_cert(gpkgname);
+
+ _d_msg(DEBUG_INFO, "end : _rpm_uninstall_pkg(%d)\n", ret);
+ return ret;
+}
+
+int _rpm_install_corexml(char *pkgfilepath, char *pkgid)
+{
+ /*validate signature and certifictae*/
+ char buff[BUF_SIZE] = {'\0'};
+ int ret = 0;
+
+ ret = _ri_verify_signatures(USR_APPS, pkgid);
+ if (ret < 0) {
+ _d_msg(DEBUG_ERR, "_ri_verify_signatures Failed : %s\n", pkgid);
+ ret = RPM_INSTALLER_ERR_SIG_INVALID;
+ goto err;
+ }
+
+ /* check : given pkgid is deactivation*/
+ ret = __ri_check_pkgid_for_deactivation(pkgid);
+ if (ret < 0) {
+ _d_msg(DEBUG_ERR, "pkgid[%s] for deactivation dont need to install.\n", pkgid);
+ goto err;
+ }
+
+ /* Parse and insert manifest in DB*/
+ ret = pkgmgr_parser_parse_manifest_for_installation(pkgfilepath, NULL);
+ if (ret < 0) {
+ _d_msg(DEBUG_RESULT, "Installing Manifest Failed : %s\n", pkgfilepath);
+ ret = RPM_INSTALLER_ERR_PACKAGE_NOT_INSTALLED;
+ goto err;
+ }
+
+ // _ri_register_cert has __ri_free_cert_chain.
+ _ri_register_cert(pkgid);
+
+ ret = RPM_INSTALLER_SUCCESS;
+
+err:
+ if (ret != 0) {
+ __ri_free_cert_chain();
+ }
+
+ return ret;
+
+}
+
+int _rpm_install_pkg(char *pkgfilepath, char *installoptions)
+{
+ int ret = 0;
+ time_t cur_time;
+ char buff[BUF_SIZE] = {'\0'};
+ char manifest[BUF_SIZE] = { '\0'};
+ manifest_x *mfx = NULL;
+ pkgmgrinfo_install_location location = 1;
+ int size = -1;
+#ifdef APP2EXT_ENABLE
+ app2ext_handle *handle = NULL;
+ GList *dir_list = NULL;
+#endif
+ const char *argv[] = {
+ INSTALL_SCRIPT, pkgfilepath, installoptions, NULL
+ };
+
+#ifdef PRE_CHECK_FOR_MANIFEST
+ char cwd[BUF_SIZE] = {'\0'};
+ int m_exist = 0;
+ /*flag to test whether app home dir is /usr or /opt*/
+ int home_dir = 0;
+ getcwd(cwd, BUF_SIZE);
+ if (cwd[0] == '\0') {
+ _d_msg(DEBUG_ERR, "getcwd() Failed\n");
+ return RPM_INSTALLER_ERR_INTERNAL;
+ }
+ _d_msg(DEBUG_ERR, "Current working directory is %s\n", cwd);
+ ret = mkdir(TEMP_DIR, 0644);
+ if (ret < 0) {
+ if (access(TEMP_DIR, F_OK) == 0) {
+ __rpm_delete_dir(TEMP_DIR);
+ ret = mkdir(TEMP_DIR, 0644);
+ if (ret < 0) {
+ _d_msg(DEBUG_ERR, "mkdir() failed\n");
+ return RPM_INSTALLER_ERR_INTERNAL;
+ }
+ } else {
+ _d_msg(DEBUG_ERR, "mkdir() failed\n");
+ return RPM_INSTALLER_ERR_INTERNAL;
+ }
+ }
+
+ ret = chdir(TEMP_DIR);
+ if (ret != 0) {
+ _d_msg(DEBUG_ERR, "chdir(%s) failed [%s]\n", TEMP_DIR, strerror(errno));
+ ret = RPM_INSTALLER_ERR_INTERNAL;
+ goto err;
+ }
+ _d_msg(DEBUG_ERR, "Switched to %s\n", TEMP_DIR);
+
+ const char *cpio_argv[] = { CPIO_SCRIPT, pkgfilepath, NULL };
+ ret = __rpm_xsystem(cpio_argv);
+
+ snprintf(manifest, BUF_SIZE, "%s/opt/share/packages/%s.xml", TEMP_DIR, gpkgname);
+ _d_msg(DEBUG_ERR, "Manifest name is %s\n", manifest);
+ if (access(manifest, F_OK)) {
+ _d_msg(DEBUG_ERR, "No rw Manifest File Found\n");
+
+ snprintf(manifest, BUF_SIZE, "%s/usr/share/packages/%s.xml", TEMP_DIR, gpkgname);
+ _d_msg(DEBUG_ERR, "Manifest ro name is %s\n", manifest);
+
+ if (access(manifest, F_OK)) {
+ _d_msg(DEBUG_ERR, "No ro Manifest File Found\n");
+ ret = RPM_INSTALLER_ERR_NO_MANIFEST;
+ goto err;
+ } else {
+ m_exist = 1;
+ home_dir = 0;
+ }
+ } else {
+ m_exist = 1;
+ home_dir = 1;
+ }
+ if (m_exist) {
+ ret = pkgmgr_parser_check_manifest_validation(manifest);
+ if(ret < 0) {
+ _d_msg(DEBUG_ERR, "Invalid manifest\n");
+ ret = RPM_INSTALLER_ERR_INVALID_MANIFEST;
+ goto err;
+ }
+ /*get package name from xml*/
+ mfx = pkgmgr_parser_process_manifest_xml(manifest);
+ if (mfx) {
+ if (gpkgname) {
+ free(gpkgname);
+ gpkgname = strdup(mfx->package);
+ }
+ }
+ pkgmgr_parser_free_manifest_xml(mfx);
+ }
+ /*check for signature and certificate*/
+ _ri_verify_signatures(TEMP_DIR, gpkgname);
+ if (ret < 0) {
+ _d_msg(DEBUG_ERR, "_ri_verify_signatures Failed : %s\n", gpkgname);
+ ret = RPM_INSTALLER_ERR_SIG_INVALID;
+ goto err;
+ }
+
+ ret = chdir(cwd);
+ if (ret != 0) {
+ _d_msg(DEBUG_ERR, "chdir(%s) failed [%s]\n", cwd, strerror(errno));
+ ret = RPM_INSTALLER_ERR_INTERNAL;
+ goto err;
+ }
+
+#endif
+
+#ifdef APP2EXT_ENABLE
+ ret = __get_location_from_xml(manifest, &location);
+ if (ret < 0) {
+ _d_msg(DEBUG_ERR, "Failed to get install location\n");
+ ret = RPM_INSTALLER_ERR_INTERNAL;
+ goto err;
+ } else {
+ if (location == PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL) {
+ ret = __get_size_from_xml(manifest, &size);
+ if (ret < 0) {
+ _d_msg(DEBUG_ERR, "Failed to get package size\n");
+ ret = RPM_INSTALLER_ERR_INTERNAL;
+ goto err;
+ }
+ }
+ }
+
+ if ((location == PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL) && size > 0) {
+ handle = app2ext_init(APP2EXT_SD_CARD);
+ if (handle == NULL) {
+ _d_msg(DEBUG_ERR, "app2ext init failed\n");
+ ret = RPM_INSTALLER_ERR_INTERNAL;
+ goto err;
+ }
+ if ((&(handle->interface) != NULL) && (handle->interface.pre_install != NULL) && (handle->interface.post_install != NULL)){
+ dir_list = __rpm_populate_dir_list();
+ if (dir_list == NULL) {
+ _d_msg(DEBUG_ERR, "\nError in populating the directory list\n");
+ app2ext_deinit(handle);
+ ret = RPM_INSTALLER_ERR_RPM_SCRIPT_WRONG_ARGS;
+ goto err;
+ }
+ ret = handle->interface.pre_install(gpkgname, dir_list, size);
+ if (ret == APP2EXT_ERROR_MMC_STATUS) {
+ _d_msg(DEBUG_ERR, "app2xt MMC is not here, go internal\n");
+ } else if (ret == APP2EXT_SUCCESS){
+ _d_msg(DEBUG_ERR, "pre_install done, go internal\n");
+ }
+ else {
+ _d_msg(DEBUG_ERR, "app2xt pre install API failed (%d)\n", ret);
+ __rpm_clear_dir_list(dir_list);
+ handle->interface.post_install(gpkgname, APP2EXT_STATUS_FAILED);
+ app2ext_deinit(handle);
+ ret = RPM_INSTALLER_ERR_INTERNAL;
+ goto err;
+ }
+ }
+ }
+#endif
+
+ ret = __rpm_xsystem(argv);
+
+ if (ret != 0) {
+ _d_msg(DEBUG_ERR, "install complete with error(%d)\n", ret);
+
+ #ifdef APP2EXT_ENABLE
+ if ((handle != NULL) && (handle->interface.post_install != NULL)){
+ __rpm_clear_dir_list(dir_list);
+ handle->interface.post_install(gpkgname, APP2EXT_STATUS_FAILED);
+ app2ext_deinit(handle);
+ }
+ #endif
+ goto err;
+ }
+
+#ifdef APP2EXT_ENABLE
+ if ((handle != NULL) && (handle->interface.post_install != NULL)){
+ __rpm_clear_dir_list(dir_list);
+ handle->interface.post_install(gpkgname, APP2EXT_STATUS_SUCCESS);
+ app2ext_deinit(handle);
+ }
+#endif
+
+ /*Parse the manifest to get install location and size. If installation fails, remove manifest info from DB*/
+ ret = pkgmgr_parser_parse_manifest_for_installation(manifest, NULL);
+ if (ret < 0) {
+ _d_msg(DEBUG_ERR, "Parsing Manifest Failed\n");
+ } else {
+ _d_msg(DEBUG_ERR, "Parsing Manifest Success\n");
+ }
+
+ /* Install Success. Store the installation time*/
+ cur_time = time(NULL);
+ snprintf(buff, BUF_SIZE, "db/app-info/%s/installed-time", gpkgname);
+ /* The time is stored in time_t format. It can be converted to
+ local time or GMT time as per the need by the apps*/
+ if(vconf_set_int(buff, cur_time)) {
+ _d_msg(DEBUG_ERR, "setting installation time failed\n");
+ vconf_unset(buff);
+ }
+ __rpm_apply_shared_privileges(gpkgname, home_dir);
+ ret = _ri_apply_perm(gpkgname);
+ if (ret != 0) {
+ _d_msg(DEBUG_ERR, "apply perm failed with err(%d)\n", ret);
+ } else {
+ _d_msg(DEBUG_INFO, "apply perm success\n");
+ }
+
+ /*Register cert info*/
+ _ri_register_cert(gpkgname);
+err:
+ __rpm_delete_dir(TEMP_DIR);
+ return ret;
+}
+
+int _rpm_upgrade_pkg(char *pkgfilepath, char *installoptions)
+{
+ int ret = 0;
+ char manifest[BUF_SIZE] = { '\0'};
+ manifest_x *mfx = NULL;
+ char buff[BUF_SIZE] = { '\0' };
+ pkgmgr_install_location location = 1;
+ int size = -1;
+#ifdef APP2EXT_ENABLE
+ app2ext_handle *handle = NULL;
+ GList *dir_list = NULL;
+#endif
+ pkgmgr_pkginfo_h pkghandle;
+
+#ifdef PRE_CHECK_FOR_MANIFEST
+ char cwd[BUF_SIZE] = {'\0'};
+ int m_exist = 0;
+ int home_dir = 0;
+ getcwd(cwd, BUF_SIZE);
+ if (cwd[0] == '\0') {
+ _d_msg(DEBUG_ERR, "getcwd() Failed\n");
+ return RPM_INSTALLER_ERR_INTERNAL;
+ }
+ _d_msg(DEBUG_ERR, "Current working directory is %s\n", cwd);
+ ret = mkdir(TEMP_DIR, 0644);
+ if (ret < 0) {
+ if (access(TEMP_DIR, F_OK) == 0) {
+ __rpm_delete_dir(TEMP_DIR);
+ ret = mkdir(TEMP_DIR, 0644);
+ if (ret < 0) {
+ _d_msg(DEBUG_ERR, "mkdir() failed\n");
+ return RPM_INSTALLER_ERR_INTERNAL;
+ }
+ } else {
+ _d_msg(DEBUG_ERR, "mkdir() failed\n");
+ return RPM_INSTALLER_ERR_INTERNAL;
+ }
+ }
+ ret = chdir(TEMP_DIR);
+ if (ret != 0) {
+ _d_msg(DEBUG_ERR, "chdir(%s) failed [%s]\n", TEMP_DIR, strerror(errno));
+ ret = RPM_INSTALLER_ERR_INTERNAL;
+ goto err;
+ }
+ _d_msg(DEBUG_ERR, "Switched to %s\n", TEMP_DIR);
+
+ const char *cpio_argv[] = { CPIO_SCRIPT, pkgfilepath, NULL };
+ ret = __rpm_xsystem(cpio_argv);
+
+ snprintf(manifest, BUF_SIZE, "%s/opt/share/packages/%s.xml", TEMP_DIR, gpkgname);
+ _d_msg(DEBUG_ERR, "Manifest name is %s\n", manifest);
+ if (access(manifest, F_OK)) {
+ _d_msg(DEBUG_ERR, "No rw Manifest File Found\n");
+
+ snprintf(manifest, BUF_SIZE, "%s/usr/share/packages/%s.xml", TEMP_DIR, gpkgname);
+ _d_msg(DEBUG_ERR, "Manifest ro name is %s\n", manifest);
+
+ if (access(manifest, F_OK)) {
+ _d_msg(DEBUG_ERR, "No ro Manifest File Found\n");
+ ret = RPM_INSTALLER_ERR_NO_MANIFEST;
+ goto err;
+ } else {
+ m_exist = 1;
+ home_dir = 0;
+ }
+ } else {
+ m_exist = 1;
+ home_dir = 1;
+ }
+
+ if (m_exist) {
+ ret = pkgmgr_parser_check_manifest_validation(manifest);
+ if(ret < 0) {
+ _d_msg(DEBUG_ERR, "Invalid manifest\n");
+ ret = RPM_INSTALLER_ERR_INVALID_MANIFEST;
+ goto err;
+ }
+ /*get package name from xml*/
+ mfx = pkgmgr_parser_process_manifest_xml(manifest);
+ if (mfx) {
+ if (gpkgname) {
+ free(gpkgname);
+ gpkgname = strdup(mfx->package);
+ }
+ }
+ pkgmgr_parser_free_manifest_xml(mfx);
+ }
+ /*check for signature and certificate*/
+ _ri_verify_signatures(TEMP_DIR, gpkgname);
+ if (ret < 0) {
+ _d_msg(DEBUG_ERR, "_ri_verify_signatures Failed : %s\n", gpkgname);
+ ret = RPM_INSTALLER_ERR_SIG_INVALID;
+ goto err;
+ }
+
+ ret = chdir(cwd);
+ if (ret != 0) {
+ _d_msg(DEBUG_ERR, "chdir(%s) failed [%s]\n", cwd, strerror(errno));
+ ret = RPM_INSTALLER_ERR_INTERNAL;
+ goto err;
+ }
+ /*Parse the manifest to get install location and size. If upgradation fails, remove manifest info from DB*/
+ ret = pkgmgr_parser_parse_manifest_for_upgrade(manifest, NULL);
+ if (ret < 0) {
+ _d_msg(DEBUG_ERR, "Parsing Manifest Failed\n");
+ ret = RPM_INSTALLER_ERR_INTERNAL;
+ goto err;
+ } else {
+ _d_msg(DEBUG_ERR, "Parsing Manifest Success\n");
+ }
+#endif
+
+#ifdef APP2EXT_ENABLE
+ ret = pkgmgr_pkginfo_get_pkginfo(gpkgname, &pkghandle);
+ if (ret < 0) {
+ _d_msg(DEBUG_ERR, "Failed to get pkginfo handle\n");
+ ret = RPM_INSTALLER_ERR_PKG_NOT_FOUND;
+ goto err;
+ } else {
+ ret = pkgmgr_pkginfo_get_install_location(pkghandle, &location);
+ if (ret < 0) {
+ _d_msg(DEBUG_ERR, "Failed to get install location\n");
+ pkgmgr_pkginfo_destroy_pkginfo(pkghandle);
+ ret = RPM_INSTALLER_ERR_INTERNAL;
+ goto err;
+ } else {
+ if (location == PM_INSTALL_LOCATION_PREFER_EXTERNAL) {
+ ret = pkgmgr_pkginfo_get_package_size(pkghandle, &size);
+ if (ret < 0) {
+ _d_msg(DEBUG_ERR, "Failed to get package size\n");
+ pkgmgr_pkginfo_destroy_pkginfo(pkghandle);
+ ret = RPM_INSTALLER_ERR_INTERNAL;
+ goto err;
+ }
+ }
+ }
+ pkgmgr_pkginfo_destroy_pkginfo(pkghandle);
+ if ((location == PM_INSTALL_LOCATION_PREFER_EXTERNAL) && size > 0) {
+ handle = app2ext_init(APP2EXT_SD_CARD);
+ if (handle == NULL) {
+ _d_msg(DEBUG_ERR, "app2ext init failed\n");
+ ret = RPM_INSTALLER_ERR_INTERNAL;
+ goto err;
+ }
+ if ((&(handle->interface) != NULL) && (handle->interface.pre_upgrade != NULL) && (handle->interface.post_upgrade != NULL)){
+ dir_list = __rpm_populate_dir_list();
+ if (dir_list == NULL) {
+ _d_msg(DEBUG_ERR, "\nError in populating the directory list\n");
+ ret = RPM_INSTALLER_ERR_RPM_SCRIPT_WRONG_ARGS;
+ app2ext_deinit(handle);
+ goto err;
+ }
+ ret = handle->interface.pre_upgrade(gpkgname, dir_list, size);
+ if (ret == APP2EXT_ERROR_MMC_STATUS || ret == APP2EXT_SUCCESS ) {
+ _d_msg(DEBUG_ERR, "app2xt MMC is not here, go internal (%d)\n", ret);
+ }
+ else {
+ _d_msg(DEBUG_ERR, "app2xt pre upgrade API failed (%d)\n", ret);
+ __rpm_clear_dir_list(dir_list);
+ handle->interface.post_upgrade(gpkgname, APP2EXT_STATUS_FAILED);
+ ret = RPM_INSTALLER_ERR_INTERNAL;
+ app2ext_deinit(handle);
+ goto err;
+ }
+ }
+ }
+ }
+#endif
+ const char *upgrade_argv[] = {UPGRADE_SCRIPT, pkgfilepath, installoptions, NULL};
+ ret = __rpm_xsystem(upgrade_argv);
+ if (ret != 0) {
+ _d_msg(DEBUG_ERR, "upgrade complete with error(%d)\n", ret);
+ /*remove manifest info*/
+ #ifdef PRE_CHECK_FOR_MANIFEST
+// pkgmgr_parser_parse_manifest_for_uninstallation(manifest, NULL);
+ #endif
+ #ifdef APP2EXT_ENABLE
+ if ((handle != NULL) && (handle->interface.post_upgrade != NULL)){
+ __rpm_clear_dir_list(dir_list);
+ handle->interface.post_upgrade(gpkgname, APP2EXT_STATUS_FAILED);
+ app2ext_deinit(handle);
+ }
+ #endif
+ goto err;
+ }
+#ifdef APP2EXT_ENABLE
+ if ((handle != NULL) && (handle->interface.post_upgrade != NULL)){
+ __rpm_clear_dir_list(dir_list);
+ handle->interface.post_upgrade(gpkgname, APP2EXT_STATUS_SUCCESS);
+ app2ext_deinit(handle);
+ }
+#endif
+
+ __rpm_apply_shared_privileges(gpkgname, home_dir);
+ ret = _ri_apply_perm(gpkgname);
+ if (ret != 0) {
+ _d_msg(DEBUG_ERR, "apply perm failed with err(%d)\n", ret);
+ } else {
+ _d_msg(DEBUG_INFO, "apply perm success\n");
+ }
+
+ /*Register cert info*/
+ _ri_unregister_cert(gpkgname);
+ _ri_register_cert(gpkgname);
+err:
+ __rpm_delete_dir(TEMP_DIR);
+ return ret;
+}
+
+int _rpm_move_pkg(char *pkgid, int move_type)
+{
+ app2ext_handle *hdl = NULL;
+ int ret = 0;
+ int movetype = -1;
+ GList *dir_list = NULL;
+
+ if (move_type == PM_MOVE_TO_INTERNAL)
+ movetype = APP2EXT_MOVE_TO_PHONE;
+ else if (move_type == PM_MOVE_TO_SDCARD)
+ movetype = APP2EXT_MOVE_TO_EXT;
+ else
+ return RPM_INSTALLER_ERR_WRONG_PARAM;
+
+ hdl = app2ext_init(APP2EXT_SD_CARD);
+ if ((hdl != NULL) && (hdl->interface.move != NULL)){
+ dir_list = __rpm_populate_dir_list();
+ if (dir_list == NULL) {
+ _d_msg(DEBUG_ERR, "\nError in populating the directory list\n");
+ return RPM_INSTALLER_ERR_RPM_SCRIPT_WRONG_ARGS;
+ }
+ ret = hdl->interface.move(pkgid, dir_list, movetype);
+ __rpm_clear_dir_list(dir_list);
+ if (ret != 0) {
+ _d_msg(DEBUG_ERR, "Failed to move app\n");
+ return RPM_INSTALLER_ERR_INTERNAL;
+ }
+ app2ext_deinit(hdl);
+ return RPM_INSTALLER_SUCCESS;
+ } else {
+ _d_msg(DEBUG_ERR,"Failed to get app2ext handle\n");
+ return RPM_INSTALLER_ERR_INTERNAL;
+ }
+}
+
+int _rpm_process_cscxml(char *csc_script)
+{
+ int ret = 0;
+ int op_type = 0;
+
+ char *path_str = NULL;
+ char *op_str = NULL;
+ char *remove_str = NULL;
+ char csc_str[BUF_SIZE] = {'\0'};
+ snprintf(csc_str, BUF_SIZE - 1, "%s:", csc_script);
+
+ /*get params from csc script*/
+ path_str = __ri_get_str(csc_str, TOKEN_PATH_STR);
+ op_str = __ri_get_str(csc_str, TOKEN_OPERATION_STR);
+ remove_str = __ri_get_str(csc_str, TOKEN_REMOVE_STR);
+ if((path_str == NULL) || (op_str == NULL) || (remove_str == NULL)){
+ _d_msg(DEBUG_ERR, "csc-info : input param is null[%s, %s, %s]\n", path_str, op_str, remove_str);
+ goto end;
+ }
+ _d_msg(DEBUG_INFO, "csc-info : path=%s, op=%s, remove=%s\n", path_str, op_str, remove_str);
+
+ /*get operation type*/
+ op_type = __ri_get_op_type(op_str);
+ if(op_type < 0){
+ _d_msg(DEBUG_ERR, "csc-info : operation error[%s, %s]\n", path_str, op_str);
+ goto end;
+ }
+
+ switch (op_type) {
+ case INSTALL_REQ:
+ ret = __ri_install_csc(path_str, remove_str);
+ break;
+
+ case UPGRADE_REQ:
+ ret = __ri_install_csc(path_str, remove_str);
+ break;
+
+ case UNINSTALL_REQ:
+ ret = __ri_uninstall_csc(path_str);
+ break;
+
+ default:
+ break;
+ }
+
+ if (ret < 0)
+ _d_msg(DEBUG_ERR, "fota-info : Fota fail [pkgid=%s, operation=%d]\n",path_str, op_type);
+
+end:
+ if(path_str)
+ free(path_str);
+ if(op_str)
+ free(op_str);
+ if(remove_str)
+ free(remove_str);
+
+ return ret;
+}
+
+int _rpm_process_fota(char *fota_script)
+{
+ int ret = 0;
+ int op_type = 0;
+ char *pkgid = NULL;
+ char *op_str = NULL;
+
+ char csc_str[BUF_SIZE] = {'\0'};
+ snprintf(csc_str, BUF_SIZE - 1, "%s:", fota_script);
+
+ /*get params from fota script*/
+ pkgid = __ri_get_str(csc_str, TOKEN_PATH_STR);
+ op_str = __ri_get_str(csc_str, TOKEN_OPERATION_STR);
+ if((pkgid == NULL) || (op_str == NULL)){
+ _d_msg(DEBUG_ERR, "fota-info : input param is null[%s, %s]\n", pkgid, op_str);
+ goto end;
+ }
+ _d_msg(DEBUG_INFO, "fota-info : path=%s, op=%s\n", pkgid, op_str);
+
+ /*get operation type*/
+ op_type = __ri_get_op_type(op_str);
+ if(op_type < 0){
+ _d_msg(DEBUG_ERR, "fota-info : operation error[%s, %s]\n", pkgid, op_str);
+ goto end;
+ }
+
+ switch (op_type) {
+ case INSTALL_REQ:
+ ret = __ri_install_fota(pkgid);
+ break;
+
+ case UPGRADE_REQ:
+ ret = __ri_upgrade_fota(pkgid);
+ break;
+
+ case UNINSTALL_REQ:
+ ret = __ri_uninstall_fota(pkgid);
+ break;
+
+ default:
+ break;
+ }
+
+ if (ret < 0)
+ _d_msg(DEBUG_ERR, "fota-info : Fota fail [pkgid=%s, operation=%d]\n",pkgid, op_type);
+
+end:
+ if(pkgid)
+ free(pkgid);
+ if(op_str)
+ free(op_str);
+
+ return ret;
+}
+
+int _rpm_process_fota_for_rw(char *fota_script)
+{
+ int ret = 0;
+ int op_type = 0;
+ char *pkgid = NULL;
+ char *op_str = NULL;
+
+ char fota_str[BUF_SIZE] = {'\0'};
+ snprintf(fota_str, BUF_SIZE - 1, "%s:", fota_script);
+
+ /*get params from fota script*/
+ pkgid = __ri_get_str(fota_str, TOKEN_PATH_STR);
+ op_str = __ri_get_str(fota_str, TOKEN_OPERATION_STR);
+ if((pkgid == NULL) || (op_str == NULL)){
+ _d_msg(DEBUG_ERR, "fota-info : input param is null[%s, %s]\n", pkgid, op_str);
+ goto end;
+ }
+ _d_msg(DEBUG_INFO, "fota-info : path=%s, op=%s\n", pkgid, op_str);
+
+ /*get operation type*/
+ op_type = __ri_get_op_type(op_str);
+ if(op_type < 0){
+ _d_msg(DEBUG_ERR, "fota-info : operation error[%s, %s]\n", pkgid, op_str);
+ goto end;
+ }
+
+ switch (op_type) {
+ case INSTALL_REQ:
+ ret = __ri_install_fota_for_rw(pkgid);
+ break;
+
+ case UPGRADE_REQ:
+ ret = __ri_upgrade_fota_for_rw(pkgid);
+ break;
+
+ case UNINSTALL_REQ:
+ ret = __ri_uninstall_fota_for_rw(pkgid);
+ break;
+
+ default:
+ break;
+ }
+
+ if (ret < 0)
+ _d_msg(DEBUG_ERR, "fota-info : Fota fail [pkgid=%s, operation=%d]\n",pkgid, op_type);
+
+end:
+ if(pkgid)
+ free(pkgid);
+ if(op_str)
+ free(op_str);
+
+ sync();
+
+ return ret;
+}
+
+int _rpm_process_enable(char *pkgid)
+{
+ int ret = 0;
+ char *manifest = NULL;
+ pkgmgrinfo_pkginfo_h handle;
+ bool is_system = 0;
+
+ _d_msg(DEBUG_ERR, "start :: pkgid[%s] enable process\n",pkgid);
+
+ ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle);
+ if ((ret == 0) && (handle != NULL)) {
+ _d_msg(DEBUG_ERR, "pkg[%s] is already installed.", pkgid);
+ pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
+ return 0;
+ }
+
+ manifest = pkgmgr_parser_get_manifest_file(pkgid);
+ if (manifest == NULL) {
+ _d_msg(DEBUG_ERR, "Failed to fetch package manifest file\n");
+ return -1;
+ }
+
+ _ri_broadcast_status_notification(pkgid, PKGMGR_INSTALLER_START_KEY_STR, PKGMGR_INSTALLER_INSTALL_EVENT_STR);
+
+ ret = pkgmgr_parser_parse_manifest_for_installation(manifest, NULL);
+ free(manifest);
+ if (ret < 0) {
+ _ri_broadcast_status_notification(pkgid, PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_FAIL_EVENT_STR);
+ _d_msg(DEBUG_ERR, "insert in db failed\n");
+ return -1;
+ }
+
+ ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle);
+ if (ret < 0) {
+ _d_msg(DEBUG_ERR, "insert in db failed\n");
+ } else {
+ ret = pkgmgrinfo_pkginfo_is_system(handle, &is_system);
+ if (is_system) {
+ pkgmgrinfo_appinfo_get_list(handle, PM_UI_APP, __ri_update_ail_info, NULL);
+ }
+ pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
+ }
+
+ /*delete disabled pkg info from backup db table*/
+ pkgmgr_parser_delete_disabled_pkg(pkgid, NULL);
+
+ _ri_broadcast_status_notification(pkgid, PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_OK_EVENT_STR);
+
+ _d_msg(DEBUG_ERR, "end :: pkgid[%s] enable process\n",pkgid);
+
+ return 0;
+}
+
+int _rpm_process_disable(char *pkgid)
+{
+ int ret = 0;
+ pkgmgrinfo_pkginfo_h handle;
+
+ _d_msg(DEBUG_ERR, "start :: pkgid[%s] disable process\n",pkgid);
+
+ ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle);
+ if ((ret < 0) || (handle == NULL)) {
+ _d_msg(DEBUG_ERR, "pkgid[%s] is already disabled\n", pkgid);
+ return 0;
+ }
+
+ _ri_broadcast_status_notification(pkgid, PKGMGR_INSTALLER_START_KEY_STR, PKGMGR_INSTALLER_UNINSTALL_EVENT_STR);
+
+ pkgmgrinfo_appinfo_get_list(handle, PM_UI_APP, __ri_check_running_app, NULL);
+ pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
+
+ ret = pkgmgr_parser_parse_manifest_for_uninstallation(pkgid, NULL);
+ if (ret < 0) {
+ _ri_broadcast_status_notification(pkgid, PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_FAIL_EVENT_STR);
+ _d_msg(DEBUG_ERR, "pkgmgr_parser_parse_manifest_for_uninstallation failed.\n");
+ return -1;
+ }
+
+ /*save disabled pkg info to backup db table*/
+ pkgmgr_parser_insert_disabled_pkg(pkgid, NULL);
+
+ _ri_broadcast_status_notification(pkgid, PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_OK_EVENT_STR);
+
+ _d_msg(DEBUG_ERR, "end :: pkgid[%s] disable process\n",pkgid);
+ return 0;
+}
+
+int _rpm_process_enabled_list(const char *enabled_list)
+{
+ char* token = NULL;
+ char delims[] = ":";
+ char pkgid[MAX_BUF_SIZE] = {'\0'};
+ char pkgid_list[MAX_BUF_SIZE] = {'\0'};
+
+ if (enabled_list == NULL)
+ return -1;
+
+ snprintf(pkgid_list, MAX_BUF_SIZE, "%s", enabled_list);
+ token = strtok(pkgid_list, delims);
+
+ while(token)
+ {
+ memset(pkgid, 0x00, sizeof(pkgid));
+ strncat(pkgid, token, strlen(token));
+
+ _rpm_process_enable(pkgid);
+
+ token = strtok(NULL, delims);
+ }
+
+ return 0;
+}
+
+int _rpm_process_disabled_list(const char *disabled_list)
+{
+ char* token = NULL;
+ char delims[] = ":";
+ char pkgid[MAX_BUF_SIZE] = {'\0'};
+ char pkgid_list[MAX_BUF_SIZE] = {'\0'};
+
+ if (disabled_list == NULL)
+ return -1;
+
+ snprintf(pkgid_list, MAX_BUF_SIZE, "%s", disabled_list);
+ token = strtok(pkgid_list, delims);
+
+ while(token)
+ {
+ memset(pkgid, 0x00, sizeof(pkgid));
+ strncat(pkgid, token, strlen(token));
+
+ _rpm_process_disable(pkgid);
+
+ token = strtok(NULL, delims);
+ }
+
+ return 0;
+}
+
--- /dev/null
+/*
+ * rpm-installer
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
+ * Jaeho Lee <jaeho81.lee@samsung.com>, Shobhit Srivastava <shobhit.s@samsung.com>
+ *
+ * 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 <pkgmgr_installer.h>
+#include <vconf.h>
+#include <errno.h>
+
+#include "rpm-installer-util.h"
+#include "rpm-installer.h"
+
+#define VCONF_LOCATION "db"
+#define VCONF_RPM_INSTALLER VCONF_LOCATION"/private/rpm-installer"
+
+#define VCONF_RPM_INSTALLER_BACKEND_STATE \
+ VCONF_RPM_INSTALLER"/state"
+#define VCONF_RPM_INSTALLER_BACKEND_STATEINFO \
+ VCONF_RPM_INSTALLER"/stateinfo"
+
+#define VCONF_RPM_INSTALLER_LAST_REQUESTINFO_COMMAND \
+ VCONF_RPM_INSTALLER"/requestinfo/command"
+#define VCONF_RPM_INSTALLER_LAST_REQUESTINFO_PKGNAME \
+ VCONF_RPM_INSTALLER"/requestinfo/pkgname"
+#define VCONF_RPM_INSTALLER_LAST_REQUESTINFO_OPTIONS \
+ VCONF_RPM_INSTALLER"/requestinfo/options"
+
+#define ERR_RETURN_LEN 10
+
+extern pkgmgr_installer *pi;
+extern char *gpkgname;
+extern int broadcast_disable;
+
+int _ri_get_backend_state()
+{
+ int ret = -1;
+ int state = -1;
+
+// _d_msg(DEBUG_INFO,"_ri_get_backend_state\n");
+ ret = vconf_get_int(VCONF_RPM_INSTALLER_BACKEND_STATE, &state);
+ if (ret == -1) {
+ _d_msg(DEBUG_ERR,
+ "_ri_get_backend_state: vconf_get_int FAIL\n");
+ } else {
+ ret = state;
+ }
+ return ret;
+}
+
+int _ri_set_backend_state(int state)
+{
+ int ret = -1;
+
+ if (state == 0) {
+ vconf_unset_recursive(VCONF_RPM_INSTALLER);
+ }
+
+// _d_msg(DEBUG_INFO,"_ri_set_backend_state\n");
+ ret = vconf_set_int(VCONF_RPM_INSTALLER_BACKEND_STATE, state);
+ if (ret == -1) {
+ _d_msg(DEBUG_ERR,
+ "_ri_set_backend_state: vconf_set_int FAIL\n");
+ }
+
+ return ret;
+}
+
+int _ri_get_backend_state_info()
+{
+ int ret = -1;
+ int state = -1;
+ ret = vconf_get_int(VCONF_RPM_INSTALLER_BACKEND_STATEINFO, &state);
+ if (ret == -1) {
+ _d_msg(DEBUG_ERR,
+ "_ri_get_backend_state_info: vconf_get_int FAIL\n");
+ } else {
+ ret = state;
+ /* _d_msg(DEBUG_INFO,"_ri_get_backend_state_info state[%d]\n", state);*/
+ }
+ return ret;
+}
+
+int _ri_set_backend_state_info(int state)
+{
+ int ret = -1;
+// _d_msg(DEBUG_INFO,"_ri_set_backend_state_info %d\n", state);
+ ret = vconf_set_int(VCONF_RPM_INSTALLER_BACKEND_STATEINFO, state);
+ if (ret == -1)
+ _d_msg(DEBUG_ERR,
+ "_ri_set_backend_state_info: vconf_set_int FAIL\n");
+
+ return ret;
+}
+
+int _ri_get_last_input_info(char **pkgid, int *preqcommand, int *poptions)
+{
+ int ret = -1;
+ if (!pkgid || !preqcommand || !poptions)
+ return -1;
+ ret = vconf_get_int(VCONF_RPM_INSTALLER_LAST_REQUESTINFO_COMMAND,
+ preqcommand);
+ if (ret == -1)
+ _d_msg(DEBUG_ERR,
+ "_ri_get_last_input_info: VCONF_RPM_INSTALLER_LAST_REQUESTINFO_COMMAND: vconf_get_int FAIL\n");
+
+ ret = vconf_get_int(VCONF_RPM_INSTALLER_LAST_REQUESTINFO_OPTIONS,
+ poptions);
+ if (ret == -1)
+ _d_msg(DEBUG_ERR,
+ "_ri_get_last_input_info: VCONF_RPM_INSTALLER_LAST_REQUESTINFO_OPTIONS: vconf_get_int FAIL\n");
+
+ *pkgid = vconf_get_str(VCONF_RPM_INSTALLER_LAST_REQUESTINFO_PKGNAME);
+ return 0;
+}
+
+void _ri_save_last_input_info(char *pkgid, int reqcommand, int options)
+{
+ keylist_t *kl = NULL;
+ kl = vconf_keylist_new();
+ int ret = -1;
+
+ ret = vconf_keylist_add_int(kl,
+ VCONF_RPM_INSTALLER_LAST_REQUESTINFO_COMMAND,
+ reqcommand);
+ if (ret == -1)
+ _d_msg(DEBUG_ERR, "vconf_keylist_add_int FAIL\n");
+ ret = vconf_keylist_add_str(kl,
+ VCONF_RPM_INSTALLER_LAST_REQUESTINFO_PKGNAME,
+ pkgid);
+ if (ret == -1)
+ _d_msg(DEBUG_ERR, "vconf_keylist_add_str FAIL\n");
+ ret = vconf_keylist_add_int(kl,
+ VCONF_RPM_INSTALLER_LAST_REQUESTINFO_OPTIONS,
+ options);
+ if (ret == -1)
+ _d_msg(DEBUG_ERR, "vconf_keylist_add_int FAIL\n");
+
+ if (vconf_set(kl))
+ _d_msg(DEBUG_ERR,
+ "_ri_save_last_input_info: Failure in writing vconf\n");
+
+ ret = vconf_keylist_free(kl);
+ if (ret == -1)
+ _d_msg(DEBUG_ERR, "vconf_keylist_free FAIL\n");
+}
+
+void _ri_broadcast_status_notification(char *pkgid, char *key, char *val)
+{
+ char *pkgid_tmp = NULL;
+ char buf[ERR_RETURN_LEN] = {'\0'};
+ int ret_val = 0;
+
+ if (broadcast_disable)
+ return;
+
+ if (gpkgname != NULL)
+ pkgid_tmp = gpkgname;
+ else
+ pkgid_tmp = pkgid;
+
+ if (pi == NULL)
+ _d_msg(DEBUG_ERR, "Failure in sending broadcast message\n");
+
+ if (strcmp(key,PKGMGR_INSTALLER_INSTALL_PERCENT_KEY_STR) == 0) {
+ ret_val = atoi(val);
+
+ _d_msg(DEBUG_INFO, "pkgid = %s, key = %s, val = %s\n", pkgid_tmp, key, val);
+
+ snprintf(buf, ERR_RETURN_LEN - 1, "%d", ret_val);
+ pkgmgr_installer_send_signal(pi, PKGTYPE, pkgid_tmp, key, buf);
+ return;
+ } else {
+ ret_val = _ri_string_to_error_no(val);
+
+ _d_msg(DEBUG_INFO, "pkgid = %s, key = %s, val = %s\n", pkgid_tmp, key, val);
+
+ if (ret_val == RPM_INSTALLER_ERR_UNKNOWN){
+ pkgmgr_installer_send_signal(pi, PKGTYPE, pkgid_tmp, key, val);
+ }
+ else{
+ snprintf(buf, ERR_RETURN_LEN - 1, "%d:%s", ret_val, val);
+ pkgmgr_installer_send_signal(pi, PKGTYPE, pkgid_tmp, key, buf);
+ }
+ }
+}
--- /dev/null
+#
+# Copyright (c) 2008 ~ 2010 Samsung Electronics Co., Ltd.
+# All rights reserved
+#
+
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+set(CMAKE_SKIP_BUILD_RPATH true)
+
+#Verbose
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/inc)
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(pkgs REQUIRED glib-2.0)
+
+FOREACH(flag ${pkgs_CFLAGS})
+ SET(pkgs_CFLAGS_str "${pkgs_CFLAGS_str} ${flag}")
+ENDFOREACH(flag)
+
+pkg_check_modules(libpkgs REQUIRED dbus-glib-1 db-util vconf sqlite3 dlog)
+
+FOREACH(flag ${libpkgs_CFLAGS})
+ SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(comm_dir "${CMAKE_SOURCE_DIR}")
+SET(comm_c_src_dir "${comm_dir}")
+
+## Additional flag
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden")
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -g -Wall")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
+
+###################################################################################################
+## for librpm-util.so (library)
+
+add_library(rpm-util STATIC
+ ${CMAKE_CURRENT_SOURCE_DIR}/rpm-installer-util.c
+ )
+set_target_properties(rpm-util PROPERTIES COMPILE_FLAGS "${pkgs_CFLAGS_str}")
+target_link_libraries(rpm-util ${libpkg_LDFLAGS})
+###################################################################################################
+
+INSTALL(TARGETS
+ rpm-util
+ DESTINATION lib/rpm-installer
+ COMPONENT RuntimeLibraries)
--- /dev/null
+/*
+ * rpm-installer
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
+ * Jaeho Lee <jaeho81.lee@samsung.com>, Shobhit Srivastava <shobhit.s@samsung.com>
+ *
+ * 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 <string.h>
+#include <stdarg.h>
+#include <sys/wait.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <wait.h>
+#include <stdio.h>
+#include <ctype.h> /* for isspace () */
+#include <string.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+#include <syslog.h>
+#include "rpm-installer-util.h"
+
+#include <dlog.h>
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#define LOG_TAG "rpm-installer"
+#endif
+
+int logging = 0x0004;
+#ifdef LOG_IN_FILE
+#define RPM_INSTALLER_LOG_FILE "/tmp/rpm-installer"
+FILE *logfile = NULL;
+#endif
+
+void _d_msg_init(char *program)
+{
+ if (logging == 0)
+ return;
+
+#ifdef LOG_IN_FILE
+ char logfilename[64] = { 0, };
+ char buffer[256] = { 0 };
+ snprintf(logfilename, 64, "%s-%s", RPM_INSTALLER_LOG_FILE, program);
+ logfile = fopen(logfilename, "a+");
+
+ if (logfile == NULL)
+ printf("Error opening log file\n");
+ else {
+ snprintf(buffer, 64, "\nLog File %s Created", logfilename);
+ fwrite(buffer, sizeof(char), strlen(buffer), logfile);
+ snprintf(buffer, 64, "\nLog Started\n");
+ fwrite(buffer, sizeof(char), strlen(buffer), logfile);
+ }
+#endif
+}
+
+void _d_msg_deinit()
+{
+ if (logging == 0)
+ return;
+
+#ifdef LOG_IN_FILE
+ if (logfile != NULL)
+ fclose(logfile);
+#endif
+}
+
+void _print_msg(int type, int exetype, char *format, ...)
+{
+ char buffer[1024] = { 0 };
+ char tbuffer[1024] = { 0 };
+ va_list args;
+ va_start(args, format);
+ vsnprintf(tbuffer, 1024, format, args);
+ va_end(args);
+
+ SECURE_LOGD("%s", tbuffer);
+
+#if 0
+ switch (type) {
+ case DEBUG_ERR:
+ LOG(LOG_ERROR, LOG_TAG, "%s", tbuffer);
+ break;
+ case DEBUG_RESULT:
+ LOG(LOG_WARN, LOG_TAG, "%s", tbuffer);
+ break;
+ case DEBUG_INFO:
+ LOG(LOG_DEBUG, LOG_TAG, "%s", tbuffer);
+ default:
+ break;
+ }
+#endif
+
+ if (logging == 0)
+ return;
+
+ if (DEBUG_ERR == (logging & type)) {
+ snprintf(buffer, 1024, "ERROR:%s", tbuffer);
+ vfprintf(stderr, format, args);
+ } else if (DEBUG_INFO == (logging & type)) {
+ snprintf(buffer, 1024, "INFO:%s", tbuffer);
+ vfprintf(stdout, format, args);
+ } else if (DEBUG_RESULT == (logging & type)) {
+ snprintf(buffer, 1024, "RESULT:%s", tbuffer);
+ vfprintf(stdout, format, args);
+ } else {
+ return;
+ }
+
+#ifdef LOG_IN_FILE
+ if (logfile != NULL)
+ fwrite(buffer, sizeof(char), strlen(buffer), logfile);
+#endif /*LOG_IN_FILE */
+}
+
+void _ri_error_no_to_string(int errnumber, char **errstr)
+{
+ if (errstr == NULL)
+ return;
+ switch (errnumber) {
+ case RPM_INSTALLER_SUCCESS:
+ *errstr = RPM_INSTALLER_SUCCESS_STR;
+ break;
+ case RPM_INSTALLER_ERR_WRONG_PARAM:
+ *errstr = RPM_INSTALLER_ERR_WRONG_PARAM_STR;
+ break;
+ case RPM_INSTALLER_ERR_DBUS_PROBLEM:
+ *errstr = RPM_INSTALLER_ERR_DBUS_PROBLEM_STR;
+ break;
+ case RPM_INSTALLER_ERR_NOT_ENOUGH_MEMORY:
+ *errstr = RPM_INSTALLER_ERR_NOT_ENOUGH_MEMORY_STR;
+ break;
+ case RPM_INSTALLER_ERR_PACKAGE_EXIST:
+ *errstr = RPM_INSTALLER_ERR_PACKAGE_EXIST_STR;
+ break;
+ case RPM_INSTALLER_ERR_PACKAGE_NOT_INSTALLED:
+ *errstr = RPM_INSTALLER_ERR_PACKAGE_NOT_INSTALLED_STR;
+ break;
+ case RPM_INSTALLER_ERR_RESOURCE_BUSY:
+ *errstr = RPM_INSTALLER_ERR_RESOURCE_BUSY_STR;
+ break;
+ case RPM_INSTALLER_ERR_UNKNOWN:
+ *errstr = RPM_INSTALLER_ERR_UNKNOWN_STR;
+ break;
+ case RPM_INSTALLER_ERR_PKG_NOT_FOUND:
+ *errstr = RPM_INSTALLER_ERR_PKG_NOT_FOUND_STR;
+ break;
+ case RPM_INSTALLER_ERR_NOT_SUPPOTED_VERSION:
+ *errstr = RPM_INSTALLER_ERR_NOT_SUPPOTED_VERSION_STR;
+ break;
+ case RPM_INSTALLER_ERR_NO_RPM_FILE:
+ *errstr = RPM_INSTALLER_ERR_NO_RPM_FILE_STR;
+ break;
+ case RPM_INSTALLER_ERR_DB_ACCESS_FAILED:
+ *errstr = RPM_INSTALLER_ERR_DB_ACCESS_FAILED_STR;
+ break;
+ case RPM_INSTALLER_ERR_RPM_OPERATION_FAILED:
+ *errstr = RPM_INSTALLER_ERR_RPM_OPERATION_FAILED_STR;
+ break;
+ case RPM_INSTALLER_ERR_PACKAGE_NOT_UPGRADED:
+ *errstr = RPM_INSTALLER_ERR_PACKAGE_NOT_UPGRADED_STR;
+ break;
+ case RPM_INSTALLER_ERR_RPM_SCRIPT_WRONG_ARGS:
+ *errstr = RPM_INSTALLER_ERR_RPM_SCRIPT_WRONG_ARGS_STR;
+ break;
+ case RPM_INSTALLER_ERR_PACKAGE_INSTALLATION_DISABLED:
+ *errstr = RPM_INSTALLER_ERR_PACKAGE_INSTALLATION_DISABLED_STR;
+ break;
+ case RPM_INSTALLER_ERR_PACKAGE_UNINSTALLATION_DISABLED:
+ *errstr = RPM_INSTALLER_ERR_PACKAGE_UNINSTALLATION_DISABLED_STR;
+ break;
+ case RPM_INSTALLER_ERR_CLEAR_DATA_FAILED:
+ *errstr = RPM_INSTALLER_ERR_CLEAR_DATA_FAILED_STR;
+ break;
+ case RPM_INSTALLER_ERR_INTERNAL:
+ *errstr = RPM_INSTALLER_ERR_INTERNAL_STR;
+ break;
+ case RPM_INSTALLER_ERR_NO_MANIFEST:
+ *errstr = RPM_INSTALLER_ERR_NO_MANIFEST_STR;
+ break;
+ case RPM_INSTALLER_ERR_INVALID_MANIFEST:
+ *errstr = RPM_INSTALLER_ERR_INVALID_MANIFEST_STR;
+ break;
+ case RPM_INSTALLER_ERR_SIG_NOT_FOUND:
+ *errstr = RPM_INSTALLER_ERR_SIG_NOT_FOUND_STR;
+ break;
+ case RPM_INSTALLER_ERR_SIG_INVALID:
+ *errstr = RPM_INSTALLER_ERR_SIG_INVALID_STR;
+ break;
+ case RPM_INSTALLER_ERR_SIG_VERIFICATION_FAILED:
+ *errstr = RPM_INSTALLER_ERR_SIG_VERIFICATION_FAILED_STR;
+ break;
+ case RPM_INSTALLER_ERR_ROOT_CERT_NOT_FOUND:
+ *errstr = RPM_INSTALLER_ERR_ROOT_CERT_NOT_FOUND_STR;
+ break;
+ case RPM_INSTALLER_ERR_CERT_INVALID:
+ *errstr = RPM_INSTALLER_ERR_CERT_INVALID_STR;
+ break;
+ case RPM_INSTALLER_ERR_CERTCHAIN_VERIFICATION_FAILED:
+ *errstr = RPM_INSTALLER_ERR_CERTCHAIN_VERIFICATION_FAILED_STR;
+ break;
+ default:
+ *errstr = RPM_INSTALLER_ERR_UNKNOWN_STR;
+ break;
+ }
+}
+
+int _ri_string_to_error_no(char *errstr)
+{
+ int errnumber = RPM_INSTALLER_ERR_UNKNOWN;
+ if (errstr == NULL)
+ return errnumber;
+
+ if (strcmp(errstr, RPM_INSTALLER_SUCCESS_STR) == 0)
+ errnumber = RPM_INSTALLER_SUCCESS;
+ else if (strcmp(errstr, RPM_INSTALLER_ERR_WRONG_PARAM_STR) == 0)
+ errnumber = RPM_INSTALLER_ERR_WRONG_PARAM;
+ else if (strcmp(errstr, RPM_INSTALLER_ERR_DBUS_PROBLEM_STR) == 0)
+ errnumber = RPM_INSTALLER_ERR_DBUS_PROBLEM;
+ else if (strcmp(errstr, RPM_INSTALLER_ERR_NOT_ENOUGH_MEMORY_STR) == 0)
+ errnumber = RPM_INSTALLER_ERR_NOT_ENOUGH_MEMORY;
+ else if (strcmp(errstr, RPM_INSTALLER_ERR_PACKAGE_EXIST_STR) == 0)
+ errnumber = RPM_INSTALLER_ERR_PACKAGE_EXIST;
+ else if (strcmp(errstr, RPM_INSTALLER_ERR_PACKAGE_NOT_INSTALLED_STR)
+ == 0)
+ errnumber = RPM_INSTALLER_ERR_PACKAGE_NOT_INSTALLED;
+ else if (strcmp(errstr, RPM_INSTALLER_ERR_RESOURCE_BUSY_STR) == 0)
+ errnumber = RPM_INSTALLER_ERR_RESOURCE_BUSY;
+ else if (strcmp(errstr, RPM_INSTALLER_ERR_UNKNOWN_STR) == 0)
+ errnumber = RPM_INSTALLER_ERR_UNKNOWN;
+ else if (strcmp(errstr, RPM_INSTALLER_ERR_PKG_NOT_FOUND_STR) == 0)
+ errnumber = RPM_INSTALLER_ERR_PKG_NOT_FOUND;
+ else if (strcmp(errstr, RPM_INSTALLER_ERR_NOT_SUPPOTED_VERSION_STR) ==
+ 0)
+ errnumber = RPM_INSTALLER_ERR_NOT_SUPPOTED_VERSION;
+ else if (strcmp(errstr, RPM_INSTALLER_ERR_NO_RPM_FILE_STR) == 0)
+ errnumber = RPM_INSTALLER_ERR_NO_RPM_FILE;
+ else if (strcmp(errstr, RPM_INSTALLER_ERR_DB_ACCESS_FAILED_STR) == 0)
+ errnumber = RPM_INSTALLER_ERR_DB_ACCESS_FAILED;
+ else if (strcmp(errstr, RPM_INSTALLER_ERR_RPM_OPERATION_FAILED_STR)
+ == 0)
+ errnumber = RPM_INSTALLER_ERR_RPM_OPERATION_FAILED;
+ else if (strcmp(errstr, RPM_INSTALLER_ERR_PACKAGE_NOT_UPGRADED_STR) ==
+ 0)
+ errnumber = RPM_INSTALLER_ERR_PACKAGE_NOT_UPGRADED;
+ else if (strcmp(errstr, RPM_INSTALLER_ERR_RPM_SCRIPT_WRONG_ARGS_STR) ==
+ 0)
+ errnumber = RPM_INSTALLER_ERR_RPM_SCRIPT_WRONG_ARGS;
+ else if (strcmp(errstr, RPM_INSTALLER_ERR_PACKAGE_INSTALLATION_DISABLED_STR) == 0)
+ errnumber = RPM_INSTALLER_ERR_PACKAGE_INSTALLATION_DISABLED;
+ else if (strcmp(errstr, RPM_INSTALLER_ERR_PACKAGE_UNINSTALLATION_DISABLED_STR) == 0)
+ errnumber = RPM_INSTALLER_ERR_PACKAGE_UNINSTALLATION_DISABLED;
+ else if (strcmp(errstr, RPM_INSTALLER_ERR_CLEAR_DATA_FAILED_STR) == 0)
+ errnumber = RPM_INSTALLER_ERR_CLEAR_DATA_FAILED;
+ else if (strcmp(errstr, RPM_INSTALLER_ERR_INTERNAL_STR) == 0)
+ errnumber = RPM_INSTALLER_ERR_INTERNAL;
+ else if (strcmp(errstr, RPM_INSTALLER_ERR_NO_MANIFEST_STR) == 0)
+ errnumber = RPM_INSTALLER_ERR_NO_MANIFEST;
+ else if (strcmp(errstr, RPM_INSTALLER_ERR_INVALID_MANIFEST_STR) == 0)
+ errnumber = RPM_INSTALLER_ERR_INVALID_MANIFEST;
+ else if (strcmp(errstr, RPM_INSTALLER_ERR_SIG_NOT_FOUND_STR) == 0)
+ errnumber = RPM_INSTALLER_ERR_SIG_NOT_FOUND;
+ else if (strcmp(errstr, RPM_INSTALLER_ERR_SIG_INVALID_STR) == 0)
+ errnumber = RPM_INSTALLER_ERR_SIG_INVALID;
+ else if (strcmp(errstr, RPM_INSTALLER_ERR_SIG_VERIFICATION_FAILED_STR) == 0)
+ errnumber = RPM_INSTALLER_ERR_SIG_VERIFICATION_FAILED;
+ else if (strcmp(errstr, RPM_INSTALLER_ERR_ROOT_CERT_NOT_FOUND_STR) == 0)
+ errnumber = RPM_INSTALLER_ERR_ROOT_CERT_NOT_FOUND;
+ else if (strcmp(errstr, RPM_INSTALLER_ERR_CERT_INVALID_STR) == 0)
+ errnumber = RPM_INSTALLER_ERR_CERT_INVALID;
+ else if (strcmp(errstr, RPM_INSTALLER_ERR_CERTCHAIN_VERIFICATION_FAILED_STR) == 0)
+ errnumber = RPM_INSTALLER_ERR_CERTCHAIN_VERIFICATION_FAILED;
+ else
+ errnumber = RPM_INSTALLER_ERR_UNKNOWN;
+
+ return errnumber;
+}
--- /dev/null
+rpm-installer (0.1.7) unstable; urgency=low
+
+ * Changed vconf key according to the guide
+ * Git: 165.213.149.219:slp/pkgs/r/rpm-installer
+ * Tag: rpm-installer_0.1.7
+
+ -- Sewook Park <sewook7.park@samsung.com> Thu, 17 May 2012 21:17:15 +0900
+
+rpm-installer (0.1.6) unstable; urgency=low
+
+ * Fixed memory consumption bug
+ * Git: 165.213.149.219:slp/pkgs/r/rpm-installer
+ * Tag: rpm-installer_0.1.6
+
+ -- Sewook Park <sewook7.park@samsung.com> Mon, 09 Apr 2012 17:52:35 +0900
+
+rpm-installer (0.1.5) unstable; urgency=low
+
+ * Fixed install bug
+ * Git: 165.213.149.219:slp/pkgs/r/rpm-installer
+ * Tag: rpm-installer_0.1.5
+
+ -- Sewook Park <sewook7.park@samsung.com> Tue, 27 Mar 2012 18:19:14 +0900
+
+rpm-installer (0.1.4) unstable; urgency=low
+
+ * Implemented backend-lib, localization, recovery and clear data
+ * Git: 165.213.149.219:slp/pkgs/r/rpm-installer
+ * Tag: rpm-installer_0.1.4
+
+ -- Sewook Park <sewook7.park@samsung.com> Fri, 16 Mar 2012 18:08:10 +0900
+
+rpm-installer (0.1.3) unstable; urgency=low
+
+ * Fixed bug for elementary modification
+ * Git: 165.213.149.219:slp/pkgs/r/rpm-installer
+ * Tag: rpm-installer_0.1.3
+
+ -- Sewook Park <sewook7.park@samsung.com> Thu, 15 Mar 2012 15:11:14 +0900
+
+rpm-installer (0.1.2) unstable; urgency=low
+
+ * Fixed code for elementary 1.0
+ * Git: 165.213.149.219:slp/pkgs/r/rpm-installer
+ * Tag: rpm-installer_0.1.2
+
+ -- Sewook Park <sewook7.park@samsung.com> Wed, 14 Mar 2012 18:27:21 +0900
+
+rpm-installer (0.1.1) unstable; urgency=low
+
+ * First release
+ * Git: 165.213.149.219:slp/pkgs/r/rpm-installer
+ * Tag: rpm-installer_0.1.1
+
+ -- Sewook Park <sewook7.park@samsung.com> Fri, 03 Feb 2012 15:30:00 +0900
--- /dev/null
+Source: rpm-installer
+Section: base
+Priority: extra
+Maintainer: Shobhit Srivastava <shobhit.s@samsung.com>, Sewook Park <sewook7.park@samsung.com>
+Build-Depends: debhelper (>= 5), libslp-setting-dev, libsqlite3-dev, libslp-db-util-dev, libdbus-glib-1-dev, libglib2.0-dev, libpkgmgr-installer-dev, libsecurity-server-client-dev, libelm-dev, libappcore-efl-dev, dlog-dev, libpkgmgr-types-dev, libevas-dev, libecore-dev, libedje-dev, libmdm-dev
+Standards-Version: 3.7.2
+
+Package: rpm-installer
+Section: base
+Architecture: any
+Depends: ${shlibs:Depends}, ${misc:Depends}
+Description: rpm installer package
+
+Package: rpm-installer-dbg
+Section: debug
+Architecture: any
+Depends: ${shlibs:Depends}, ${misc:Depends} rpm-installer
+Description: rpm installer debug package
--- /dev/null
+#Fri Feb 03 19:14:26 KST 2012
+Package=rpm-installer
+AppInstallPath=/usr
--- /dev/null
+#Fri Feb 03 17:26:45 KST 2012
+Name=rpm-installer
+Type=Application
+Exec=/usr/etc/package-manager/backend/rpm
+Icon=
+Comment=
+MimeType=application/x-rpm
+Hidden=true
+Version=0.1.1
+X-SLP-TaskManage=true
+X-SLP-Multiple=true
--- /dev/null
+usr/bin
+usr/sbin
--- /dev/null
+CMakeLists.txt
--- /dev/null
+#!/bin/sh
+
+mkdir -p /usr/etc/package-manager/backend
+chmod 755 /usr/lib/rpm-installer/librpm-util.a
+chmod 755 /usr/lib/debug/usr/bin/rpm-backend
--- /dev/null
+@PREFIX@/lib/rpm-installer/librpm-util.a
+@PREFIX@/bin/rpm-backend
+@PREFIX@/bin/install_rpm_package.sh
+@PREFIX@/bin/install_rpm_package_with_dbpath_ro.sh
+@PREFIX@/bin/install_rpm_package_with_dbpath_rw.sh
+@PREFIX@/bin/uninstall_rpm_package.sh
+@PREFIX@/bin/upgrade_rpm_package.sh
+@PREFIX@/bin/upgrade_rpm_package_with_dbpath_ro.sh
+@PREFIX@/bin/upgrade_rpm_package_with_dbpath_rw.sh
+@PREFIX@/bin/query_rpm_package.sh
+@PREFIX@/bin/cpio_rpm_package.sh.in
+@PREFIX@/bin/cpio_rpm_package_update_xml.sh.in
+@PREFIX@/usr/share/data
--- /dev/null
+#!/bin/sh
+
+mkdir -p /usr/etc/package-manager/backend
+ln -sf /usr/bin/rpm-backend /usr/etc/package-manager/backend/rpm
+ln -sf /usr/lib/libnativerpm.so /usr/etc/package-manager/backendlib/librpm.so
+if [ "${USER}" = "root" ]
+then
+ chown 5000:5000 /usr/lib/rpm-installer/librpm-util.a
+ chown 5000:5000 /usr/bin/rpm-backend
+fi
+
+chmod 755 /usr/lib/rpm-installer/librpm-util.a
+chmod 755 /usr/bin/rpm-backend
+
--- /dev/null
+#!/usr/bin/make -f
+# -*- makefile -*-
+# Sample debian/rules that uses debhelper.
+# This file was originally written by Joey Hess and Craig Small.
+# As a special exception, when this file is copied by dh-make into a
+# dh-make output file, you may use that output file without restriction.
+# This special exception was added by Craig Small in version 0.37 of dh-make.
+
+# Uncomment this to turn on verbose mode.
+#export DH_VERBOSE=1
+
+include debian/desktop.slp
+include debian/control.slp
+
+PKGDIR = debian/$(Package)
+DESKTOPFILE = debian/desktop.slp
+DESKTOPDIR = usr/share/install-info/application
+
+CFLAGS = -Wall -g
+
+ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
+ CFLAGS += -O0
+else
+ CFLAGS += -O2
+endif
+
+configure: configure-stamp
+configure-stamp:
+ dh_testdir
+ # Add here commands to configure the package.
+ rm -rf Makefile CMakeCache.txt CMakeFiles cmake_install.cmake install_manifest.txt *.deb
+ cmake . -DCMAKE_INSTALL_PREFIX=/usr
+ rm -rf CMakeFiles/CompilerIdC*
+ touch configure-stamp
+
+
+build: build-stamp
+
+build-stamp: configure-stamp
+ dh_testdir
+
+ # Add here commands to compile the package.
+ $(MAKE)
+ #docbook-to-man debian/native-installer.sgml > native-installer.1
+
+ touch $@
+
+clean:
+ dh_testdir
+ dh_testroot
+ rm -f build-stamp configure-stamp
+ # Add here commands to clean up after the build process.
+ -$(MAKE) clean
+ dh_clean
+ rm -rf Makefile CMakeCache.txt CMakeFiles cmake_install.cmake install_manifest.txt *.deb
+ cd backend && rm -rf Makefile CMakeCache.txt CMakeFiles cmake_install.cmake install_manifest.txt *.deb
+ cd backend-lib && rm -rf Makefile CMakeCache.txt CMakeFiles cmake_install.cmake install_manifest.txt *.deb
+ rm -f backend/install_rpm_package.sh backend/install_rpm_package_with_dbpath_ro.sh backend/install_rpm_package_with_dbpath_rw.sh backend/uninstall_rpm_package.sh backend/upgrade_rpm_package.sh backend/upgrade_rpm_package_with_dbpath_ro.sh backend/upgrade_rpm_package_with_dbpath_rw.sh backend/query_rpm__package.sh backend/cpio_rpm_package.sh backend/cpio_rpm_package_update_xml.sh
+ cd frontend && rm -rf Makefile CMakeCache.txt CMakeFiles cmake_install.cmake install_manifest.txt *.deb *.sh rpm-backend
+ cd common && rm -rf Makefile CMakeCache.txt CMakeFiles cmake_install.cmake install_manifest.txt *.deb *.a
+ cd frontend && rm -rf Makefile CMakeCache.txt CMakeFiles cmake_install.cmake install_manifest.txt *.deb
+ cd po && rm -rf Makefile CMakeCache.txt CMakeFiles cmake_install.cmake install_manifest.txt *.deb *.mo
+ rm -rf $(CURDIR)/debian/rpm-installer
+ rm -rf $(CURDIR)/debian/rpm-installer-dbg
+
+install: build
+ dh_testdir
+ dh_testroot
+ dh_clean -k
+ dh_installdirs
+
+ # Add here commands to install the package into debian/rpm-installer.
+ $(MAKE) DESTDIR=$(CURDIR)/$(PKGDIR) install
+# mkdir -p $(CURDIR)/$(PKGDIR)/$(DESKTOPDIR)
+# cp $(DESKTOPFILE) $(CURDIR)/$(PKGDIR)/$(DESKTOPDIR)/$(Package).desktop
+
+
+# Build architecture-independent files here.
+binary-indep: build install
+# We have nothing to do by default.
+
+# Build architecture-dependent files here.
+binary-arch: build install
+ dh_testdir
+ dh_testroot
+ dh_installchangelogs
+ dh_installdocs
+ dh_installexamples
+# cp $(DESKTOPFILE) $(CURDIR)/debian/native-installer/$(DESKTOPDIR)/$(Package).desktop
+# dh_install
+# dh_installmenu
+# dh_installdebconf
+# dh_installlogrotate
+# dh_installemacsen
+# dh_installpam
+# dh_installmime
+# dh_python
+# dh_installinit
+# dh_installcron
+# dh_installinfo
+ dh_installman
+ dh_link
+ dh_strip --dbg-package=$(Package)-dbg
+ dh_compress
+ dh_fixperms
+# dh_perl
+# dh_makeshlibs
+ dh_installdeb
+ dh_shlibdeps
+ dh_gencontrol
+ dh_md5sums
+ dh_builddeb
+
+binary: binary-indep binary-arch
+.PHONY: build clean binary-indep binary-arch binary install configure
--- /dev/null
+#
+# Copyright (c) 2008 ~ 2010 Samsung Electronics Co., Ltd.
+# All rights reserved
+#
+
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+set(CMAKE_SKIP_BUILD_RPATH true)
+
+#Verbose
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/inc ${CMAKE_SOURCE_DIR}/backend/inc ${CMAKE_SOURCE_DIR}/backend/src/inc ${CMAKE_CURRENT_SOURCE_DIR}/inc)
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(pkgs REQUIRED pkgmgr pkgmgr-installer pkgmgr-parser pkgmgr-info pkgmgr-installer-status-broadcast-server security-server vconf sqlite3 dbus-glib-1 glib-2.0 db-util elementary appcore-efl libxml-2.0 app2sd cert-svc
+xmlsec1 libprivilege-control capi-appfw-app-manager aul)
+
+FOREACH(flag ${pkgs_CFLAGS})
+ SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+pkg_check_modules(libpkgs REQUIRED security-server pkgmgr pkgmgr-installer pkgmgr-parser pkgmgr-info pkgmgr-installer-status-broadcast-server vconf sqlite3 dbus-glib-1 glib-2.0 db-util elementary appcore-efl libxml-2.0 app2sd cert-svc
+xmlsec1 libprivilege-control capi-appfw-app-manager aul)
+
+FOREACH(flag ${libpkgs_CFLAGS})
+ SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+pkg_check_modules(STATUS pkgmgr-installer-status-broadcast-server pkgmgr pkgmgr-installer pkgmgr-parser libxml-2.0 app2sd pkgmgr-info cert-svc
+xmlsec1 libprivilege-control capi-appfw-app-manager aul)
+link_directories (${STATUS_LIBRARY_DIRS})
+include_directories (${STATUS_INCLUDE_DIRS})
+
+pkg_check_modules(COMMCLIENT pkgmgr-installer-client)
+link_directories (${COMMCLIENT_LIBRARY_DIRS})
+include_directories (${COMMCLIENT_INCLUDE_DIRS})
+
+pkg_check_modules(APPCODEEFL appcore-efl evas ecore edje ecore-input ecore-x)
+link_directories (${APPCODEEFL_LIBRARY_DIRS})
+include_directories (${APPCODEEFL_INCLUDE_DIRS})
+
+pkg_check_modules(SECURITYSERVER security-server)
+link_directories (${SECURITYSERVER_LIBRARY_DIRS})
+include_directories (${SECURITYSERVER_INCLUDE_DIRS})
+
+## DEFINITIONS
+ADD_DEFINITIONS("-DAPP_DIR=\"${CMAKE_INSTALL_PREFIX}\"")
+ADD_DEFINITIONS("-DPACKAGE=\"${PROJECT_NAME}\"")
+ADD_DEFINITIONS("-DXMLSEC_CRYPTO_OPENSSL")
+
+link_directories ("${STATUS_LIBRARY_DIRS} /usr/lib")
+include_directories (${STATUS_INCLUDE_DIRS})
+find_library(RPM_LIBRARY rpm "/usr/lib")
+
+
+SET(backend_dir "${CMAKE_CURRENT_SOURCE_DIR}/../backend")
+SET(backend_inc_dir "${backend_dir}/include")
+SET(backend_c_src_dir "${backend_dir}/src")
+SET(backend_script_dir "${backend_dir}/scripts")
+SET(SCRIPTS_DIR "${backend_script_dir}")
+
+SET(frontend_dir "${CMAKE_CURRENT_SOURCE_DIR}")
+SET(frontend_inc_dir "${frontend_dir}/inc")
+SET(frontend_c_src_dir "${frontend_dir}/src")
+SET(frontend_c_ui_src_dir "${frontend_dir}/ui/src")
+SET(frontend_c_ui_inc_dir "${frontend_dir}/ui/include")
+
+
+
+## Additional flag
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden")
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -g -Wall -rdynamic")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
+
+####################################################################################################
+## for rpm-backend (binary)
+SET(rpm-backend_SOURCES ${backend_c_src_dir}/core/rpm-installer-core.c ${backend_c_src_dir}/core/rpm-installer-tool.c ${backend_c_src_dir}/rpm/rpm-installer.c ${backend_c_src_dir}/rpm/rpm-installer-signature.c ${backend_c_src_dir}/rpm/rpm-installer-privilege.c ${backend_c_src_dir}/vconf/rpm-vconf-intf.c ${frontend_c_src_dir}/rpm-appcore-intf.c ${frontend_c_src_dir}/rpm-cmdline.c ${frontend_c_ui_src_dir}/rpm-homeview.c)
+
+SET(rpm-backend_CFLAGS " -I. -I/usr/include/rpm -I${backend_inc_dir} -I${frontend_inc_dir} -I${frontend_c_ui_inc_dir} ${pkg_CFLAGS}")
+SET(rpm-backend_LDFLAGS ${pkgs_LDFLAGS})
+
+ADD_EXECUTABLE(rpm-backend ${rpm-backend_SOURCES})
+TARGET_LINK_LIBRARIES(rpm-backend rpm-util "rpm" "rpmio" "dl")
+TARGET_LINK_LIBRARIES(rpm-backend ${libpkgs_LDFLAGS})
+TARGET_LINK_LIBRARIES(rpm-backend ${COMMCLIENT_LIBRARIES})
+TARGET_LINK_LIBRARIES(rpm-backend ${APPCODEEFL_LIBRARIES})
+TARGET_LINK_LIBRARIES(rpm-backend ${SECURITYSERVER_LIBRARIES})
+TARGET_LINK_LIBRARIES(rpm-backend ${STATUS_LIBRARIES})
+
+SET_TARGET_PROPERTIES(rpm-backend PROPERTIES COMPILE_FLAGS "${rpm-backend_CFLAGS}")
+####################################################################################################
+
+#SET(RESOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ui/res")
+
+# INSTALL
+
+MESSAGE("${CLEAN_FILE_LIST}")
+SET_DIRECTORY_PROPERTIES(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${CLEAN_FILE_LIST}")
+
+
+
+###################################################################################################i
+configure_file(${backend_script_dir}/install_rpm_package.sh.in ${CMAKE_CURRENT_BINARY_DIR}/install_rpm_package.sh @ONLY)
+configure_file(${backend_script_dir}/install_rpm_package_with_dbpath_ro.sh.in ${CMAKE_CURRENT_BINARY_DIR}/install_rpm_package_with_dbpath_ro.sh @ONLY)
+configure_file(${backend_script_dir}/install_rpm_package_with_dbpath_rw.sh.in ${CMAKE_CURRENT_BINARY_DIR}/install_rpm_package_with_dbpath_rw.sh @ONLY)
+configure_file(${backend_script_dir}/uninstall_rpm_package.sh.in ${CMAKE_CURRENT_BINARY_DIR}/uninstall_rpm_package.sh @ONLY)
+configure_file(${backend_script_dir}/upgrade_rpm_package.sh.in ${CMAKE_CURRENT_BINARY_DIR}/upgrade_rpm_package.sh @ONLY)
+configure_file(${backend_script_dir}/upgrade_rpm_package_with_dbpath_ro.sh.in ${CMAKE_CURRENT_BINARY_DIR}/upgrade_rpm_package_with_dbpath_ro.sh @ONLY)
+configure_file(${backend_script_dir}/upgrade_rpm_package_with_dbpath_rw.sh.in ${CMAKE_CURRENT_BINARY_DIR}/upgrade_rpm_package_with_dbpath_rw.sh @ONLY)
+configure_file(${backend_script_dir}/query_rpm_package.sh.in ${CMAKE_CURRENT_BINARY_DIR}/query_rpm_package.sh @ONLY)
+configure_file(${backend_script_dir}/cpio_rpm_package.sh.in ${CMAKE_CURRENT_BINARY_DIR}/cpio_rpm_package.sh @ONLY)
+configure_file(${backend_script_dir}/cpio_rpm_package_update_xml.sh.in ${CMAKE_CURRENT_BINARY_DIR}/cpio_rpm_package_update_xml.sh @ONLY)
+configure_file(${backend_script_dir}/post_script_rpm.sh.in ${CMAKE_CURRENT_BINARY_DIR}/post_script_rpm.sh @ONLY)
+
+INSTALL(FILES
+ ${CMAKE_CURRENT_BINARY_DIR}/install_rpm_package.sh
+ ${CMAKE_CURRENT_BINARY_DIR}/install_rpm_package_with_dbpath_ro.sh
+ ${CMAKE_CURRENT_BINARY_DIR}/install_rpm_package_with_dbpath_rw.sh
+ ${CMAKE_CURRENT_BINARY_DIR}/uninstall_rpm_package.sh
+ ${CMAKE_CURRENT_BINARY_DIR}/upgrade_rpm_package.sh
+ ${CMAKE_CURRENT_BINARY_DIR}/upgrade_rpm_package_with_dbpath_ro.sh
+ ${CMAKE_CURRENT_BINARY_DIR}/upgrade_rpm_package_with_dbpath_rw.sh
+ ${CMAKE_CURRENT_BINARY_DIR}/query_rpm_package.sh
+ ${CMAKE_CURRENT_BINARY_DIR}/cpio_rpm_package.sh
+ ${CMAKE_CURRENT_BINARY_DIR}/cpio_rpm_package_update_xml.sh
+ ${CMAKE_CURRENT_BINARY_DIR}/post_script_rpm.sh
+ DESTINATION bin)
+
+
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/rpm-installer-config.ini DESTINATION /usr/etc)
+INSTALL(TARGETS rpm-backend DESTINATION bin PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_WRITE)
+
--- /dev/null
+/*
+ * rpm-installer
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
+ * Jaeho Lee <jaeho81.lee@samsung.com>, Shobhit Srivastava <shobhit.s@samsung.com>
+ *
+ * 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.
+ *
+ */
+
+#ifndef __RPM_FRONTEND_H_
+#define __RPM_FRONTEND_H_
+
+#include <Elementary.h>
+#include <pkgmgr_installer.h>
+#include <bundle.h>
+
+#ifndef APP_DIR
+#define APP_DIR "/usr"
+#endif /* APP_DIR */
+
+#ifndef LOCALE_PATH
+#define LOCALE_PATH APP_DIR"/share/locale"
+#endif /* LOCALE_PATH */
+
+#ifndef PACKAGE
+#define PACKAGE "rpm-installer"
+#endif /* PACKAGE */
+
+enum command {
+ INVALID_CMD = -1,
+ INSTALL_CMD = 1,
+ DELETE_CMD = 2,
+ UPDATE_CMD = 3,
+ RECOVER_CMD = 4,
+ CLEARDATA_CMD = 5,
+ MOVE_CMD = 6,
+ SMACK_CMD = 7,
+ EFLWGT_INSTALL_CMD = 8,
+ EFLWGT_DELETE_CMD = 9,
+ ENABLE_CMD = 10,
+ DISABLE_CMD = 11,
+ RPM_CMD_MAX = 12,
+};
+
+struct ri_frontend_cmdline_arg_t {
+ int req_cmd;
+ char *pkgid;
+ char *keyid;
+ int quiet;
+ int move_type;
+};
+typedef struct ri_frontend_cmdline_arg_t ri_frontend_cmdline_arg;
+
+struct ri_frontend_data_t {
+ ri_frontend_cmdline_arg *args;
+ char *security_cookie;
+ char *error;
+};
+typedef struct ri_frontend_data_t ri_frontend_data;
+
+struct appdata {
+ Evas *evas;
+ Evas_Object *win_main;
+ Evas_Coord root_w;
+ Evas_Coord root_h;
+ Evas_Object *main_view; /* for main view layout */
+ Evas_Object *scrollbar_label;
+};
+
+int app_create(void *user_data);
+int app_terminate(void *user_data);
+int app_pause(void *user_data);
+int app_resume(void *user_data);
+int app_reset(bundle *b, void *user_data);
+/*mode is actually an enum defined in appcore [enum appcore_rm]*/
+int app_rotation(int mode, void *user_data);
+
+int _ri_cmdline_destroy(ri_frontend_data *data);
+int _ri_cmdline_process(ri_frontend_data *data);
+int _ri_parse_cmdline(int argc, char **argv, ri_frontend_cmdline_arg *data);
+void _ri_stat_cb(const char *pkgid, const char *key, const char *val);
+
+#endif /* __RPM_FRONTEND_H_ */
--- /dev/null
+signature=off
--- /dev/null
+/*
+ * rpm-installer
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
+ * Jaeho Lee <jaeho81.lee@samsung.com>, Shobhit Srivastava <shobhit.s@samsung.com>
+ *
+ * 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 <stdio.h>
+#include <pthread.h>
+
+#include <Elementary.h>
+#include <appcore-efl.h>
+#include <string.h>
+#include <glib-object.h>
+
+#include "rpm-frontend.h"
+#include "rpm-homeview.h"
+#include "rpm-installer-util.h"
+#include "rpm-installer.h"
+#include <pkgmgr_installer.h>
+
+#define CONFIG_PATH "/usr/etc/rpm-installer-config.ini"
+static void __ri_start_processing(void *user_data);
+static int __ri_is_signature_verification_enabled();
+
+int ret_val = -1;
+/*flag to check whether signature verification is on/off*/
+int sig_enable = 0;
+int broadcast_disable = 0;
+struct appdata ad;
+extern char scrolllabel[256];
+extern ri_frontend_data front_data;
+pkgmgr_installer *pi = NULL;
+
+
+static int __ri_is_signature_verification_enabled()
+{
+ char buffer[1024] = {'\0'};
+ char *p = NULL;
+ FILE *fi = NULL;
+ int len = 0;
+ int ret = 0;
+ fi = fopen(CONFIG_PATH, "r");
+ if (fi == NULL) {
+ _d_msg(DEBUG_ERR, "Failed to open config file [%s]\n", CONFIG_PATH);
+ return 0;
+ }
+ while (fgets(buffer, 1024, fi) != NULL) {
+ /* buffer will be like signature=off\n\0*/
+ if (strncmp(buffer, "signature", strlen("signature")) == 0) {
+ len = strlen(buffer);
+ /*remove newline character*/
+ buffer[len - 1] = '\0';
+ p = strchr(buffer, '=');
+ if (p) {
+ p++;
+ if (strcmp(p, "on") == 0)
+ ret = 1;
+ else
+ ret = 0;
+ }
+ } else {
+ continue;
+ }
+ }
+ fclose(fi);
+ return ret;
+}
+
+/**< Called before main loop */
+int app_create(void *user_data)
+{
+
+ int ret = 0;
+ struct appdata *data = (struct appdata *)user_data;
+ /*In case of downgrade, popup should be shown even if quiet mode*/
+ ret = _ri_frontend_launch_main_view(data);
+ return ret;
+}
+
+/**< Called after main loop */
+int app_terminate(void *user_data)
+{
+ struct appdata *data = (struct appdata *)user_data;
+ ri_frontend_cmdline_arg *fdata = front_data.args;
+ if (fdata->quiet == 0) {
+ _ri_destroy_home_view(data);
+ }
+ return 0;
+}
+
+/**< Called when every window goes back */
+int app_pause(void *user_data)
+{
+ return 0;
+}
+
+/**< Called when any window comes on top */
+int app_resume(void *user_data)
+{
+ return 0;
+}
+
+/**< Called at the first idler*/
+int app_reset(bundle *b, void *user_data)
+{
+ return 0;
+}
+
+/**< Called at rotate device*/
+int app_rotation(int mode, void *user_data)
+{
+ if (user_data == NULL) {
+ _d_msg(DEBUG_ERR, "arg supplied is NULL \n");
+ return -1;
+ }
+ struct appdata *data = (struct appdata *)user_data;
+ int angle;
+ switch (mode) {
+ case APPCORE_RM_LANDSCAPE_NORMAL:
+ angle = -90;
+ break;
+
+ case APPCORE_RM_LANDSCAPE_REVERSE:
+ angle = 90;
+ break;
+
+ case APPCORE_RM_PORTRAIT_REVERSE:
+ angle = 180;
+ break;
+
+ case APPCORE_RM_UNKNOWN:
+ case APPCORE_RM_PORTRAIT_NORMAL:
+ default:
+ angle = 0;
+ break;
+ }
+
+ return 0;
+}
+
+Eina_Bool show_popup_cb(void *data)
+{
+ /*Avoid log printing as it is an idler function*/
+ int state = -1;
+ char message[256] = {'\0'};
+ state = _ri_get_backend_state_info();
+ switch (state) {
+ case REQUEST_ACCEPTED:
+ break;
+ case GOT_PACKAGE_INFO_SUCCESSFULLY:
+ break;
+ case REQUEST_PENDING:
+ strncpy(message, _("Continue Downgrade?"), 255);
+ _ri_package_downgrade_information(message);
+ /*request is not completed yet. We just got confirmation
+ from user whether to downgrade or not*/
+ _ri_set_backend_state_info(REQUEST_ACCEPTED);
+ break;
+ case REQUEST_COMPLETED:
+ default:
+ if (front_data.args->quiet == 0) {
+ _ri_frontend_update_progress_info(&ad, scrolllabel);
+ return 0;
+ } else
+ elm_exit();
+ break;
+ }
+
+ return 1;
+}
+
+static void __ri_start_processing(void *user_data)
+{
+ int ret = 0;
+ if (user_data == NULL) {
+ _d_msg(DEBUG_ERR, "arg supplied is NULL \n");
+ return;
+ }
+ ri_frontend_data *data = (ri_frontend_data *) user_data;
+ g_type_init();
+ ret = _ri_cmdline_process(data);
+ ret_val = ret;
+ _ri_cmdline_destroy(data);
+
+}
+
+int main(int argc, char *argv[])
+{
+ int ret = 0;
+ int is_eflwgt = 0;
+ ri_frontend_cmdline_arg *data = NULL;
+ struct appcore_ops ops;
+ ops.create = app_create;
+ ops.terminate = app_terminate;
+ ops.pause = app_pause;
+ ops.resume = app_resume;
+ ops.reset = app_reset;
+ ops.data = &ad;
+ ecore_init();
+ appcore_set_i18n(PACKAGE, LOCALE_PATH);
+ _d_msg_init("rpm-installer");
+ /*get signature verification config*/
+ sig_enable = __ri_is_signature_verification_enabled();
+ _d_msg(DEBUG_INFO, "Signature Verification Mode is [%d]\n", sig_enable);
+
+
+ data = (ri_frontend_cmdline_arg *) calloc(1,
+ sizeof
+ (ri_frontend_cmdline_arg));
+ if (data == NULL) {
+ _d_msg(DEBUG_ERR, "Not Enough Memory\n");
+ ret = RPM_INSTALLER_ERR_NOT_ENOUGH_MEMORY;
+ goto ERROR;
+ }
+ data->keyid = NULL;
+ data->pkgid = NULL;
+ data->quiet = 0;
+ data->req_cmd = INVALID_CMD;
+ data->move_type = -1;
+
+ /* We need to use pkgmgr_installer_receive request()
+ to parse the arguments */
+ if ((ret =
+ _ri_parse_cmdline(argc, argv, data)) != RPM_INSTALLER_SUCCESS) {
+ _d_msg(DEBUG_ERR, "_ri_parse_cmdline failed \n");
+ goto ERROR;
+ }
+
+ /*check downloadable rpm*/
+ if (strstr(data->keyid, ".wgt") != NULL) {
+ _d_msg(DEBUG_ERR, "[%s] is eflwgt package.\n", data->pkgid);
+ if (data->req_cmd == INSTALL_CMD) {
+ data->req_cmd = EFLWGT_INSTALL_CMD;
+ } else if (data->req_cmd == DELETE_CMD) {
+ data->req_cmd = EFLWGT_DELETE_CMD;
+ } else {
+ _d_msg(DEBUG_ERR, "unsupported command.\n");
+ goto ERROR;
+ }
+ }
+
+ if (strstr(data->keyid, "change-state") != NULL) {
+ _d_msg(DEBUG_ERR, "change-state for [%s]\n", data->pkgid);
+ if (data->req_cmd == INSTALL_CMD) {
+ data->req_cmd = ENABLE_CMD;
+ } else if (data->req_cmd == DELETE_CMD) {
+ data->req_cmd = DISABLE_CMD;
+ } else {
+ _d_msg(DEBUG_ERR, "unsupported command.\n");
+ goto ERROR;
+ }
+ }
+
+ front_data.args = data;
+ front_data.security_cookie = NULL;
+ front_data.error = NULL;
+
+ __ri_start_processing(&front_data);
+
+ /*The installer has finished the installation/uninstallation.
+ Now, if it was a non quiet operation we need to show the popup. */
+ if ((data->req_cmd == SMACK_CMD) || (data->req_cmd == EFLWGT_INSTALL_CMD) || (data->req_cmd == EFLWGT_DELETE_CMD) || (data->req_cmd == ENABLE_CMD) || (data->req_cmd == DISABLE_CMD)){
+ goto ERROR;
+ }
+
+ ecore_idler_add(show_popup_cb, NULL);
+
+ _d_msg(DEBUG_RESULT, "About to run EFL Main Loop");
+ appcore_efl_main(PACKAGE, &argc, &argv, &ops);
+ _d_msg(DEBUG_RESULT, "%d\n", ret_val);
+
+ _d_msg_deinit();
+ if (pi) {
+ pkgmgr_installer_free(pi);
+ pi = NULL;
+ }
+
+ if(!ret_val)
+ sync();
+
+ return ret_val;
+
+ ERROR:
+ if (data) {
+ if (data->pkgid) {
+ free(data->pkgid);
+ data->pkgid = NULL;
+ }
+ if (data->keyid) {
+ free(data->keyid);
+ data->keyid = NULL;
+ }
+ free(data);
+ data = NULL;
+ }
+ _d_msg(DEBUG_INFO, "%d\n", ret);
+ _d_msg_deinit();
+ return ret;
+
+}
--- /dev/null
+/*
+ * rpm-installer
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
+ * Jaeho Lee <jaeho81.lee@samsung.com>, Shobhit Srivastava <shobhit.s@samsung.com>
+ *
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <getopt.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <appcore-efl.h>
+#include <pkgmgr_installer.h>
+#include <security-server.h>
+#include "rpm-frontend.h"
+#include "rpm-installer-util.h"
+#include "rpm-installer.h"
+#include "rpm-homeview.h"
+
+#define _FIX_POP_UP_
+extern struct appdata ad;
+extern int ret_val;
+extern pkgmgr_installer *pi;
+ri_frontend_data front_data;
+char scrolllabel[256];
+int move_type;
+
+static void __ri_show_usage(char **arg);
+static int __ri_process_request(ri_frontend_cmdline_arg *fdata);
+
+static void __ri_show_usage(char **arg)
+{
+
+ int i = 0;
+ char buffer[256];
+ char buff[256] = "";
+ while (arg[i] != NULL) {
+ snprintf(buffer, 256, "%s %s", buff, arg[i]);
+ strncpy(buff, buffer, 255);
+ i++;
+ }
+
+ _d_msg(DEBUG_INFO, "%s\n", buffer);
+ _d_msg(DEBUG_INFO,
+ "\nrpm-backend usage\n rpm-backend -k <keyid> <command> <pkgid | pkg_path> [-q] \n\n");
+ _d_msg(DEBUG_INFO, "<Commands> \n");
+ _d_msg(DEBUG_INFO,
+ "\t -i <package file path> : install package file \n");
+ _d_msg(DEBUG_INFO,
+ "\t -k <keyid> : key id file \n");
+ _d_msg(DEBUG_INFO,
+ "\t -r : (recover). Must ignore specific package name or path \n");
+ _d_msg(DEBUG_INFO,
+ "\t -d <package name> : delete a package with package name \n");
+ _d_msg(DEBUG_INFO,
+ "\t -q : (quiet) run in background without any user interaction \n");
+ _d_msg(DEBUG_INFO,
+ "\t -s : (smack) apply smack rule and set smack label\n");
+}
+
+int _ri_parse_cmdline(int argc, char **argv, ri_frontend_cmdline_arg *data)
+{
+ int req_cmd = INVALID_CMD;
+ const char *pkgid = NULL;
+ int quiet = 0;
+ const char *pkeyid = NULL;
+ int ret = 0;
+ int move_type = -1;
+ pi = pkgmgr_installer_new();
+ if (!pi) {
+ _d_msg(DEBUG_ERR,
+ "Failure in creating the pkgmgr_installer object \n");
+ return RPM_INSTALLER_ERR_WRONG_PARAM;
+ }
+ ret = pkgmgr_installer_receive_request(pi, argc, argv);
+ if (ret) {
+ _d_msg(DEBUG_ERR, "pkgmgr_installer_receive_request failed \n");
+ return RPM_INSTALLER_ERR_WRONG_PARAM;
+ }
+ ret = pkgmgr_installer_get_request_type(pi);
+ switch (ret) {
+ case PKGMGR_REQ_INSTALL:
+ req_cmd = INSTALL_CMD;
+ break;
+ case PKGMGR_REQ_UNINSTALL:
+ req_cmd = DELETE_CMD;
+ break;
+ case PKGMGR_REQ_RECOVER:
+ req_cmd = RECOVER_CMD;
+ break;
+ case PKGMGR_REQ_CLEAR:
+ req_cmd = CLEARDATA_CMD;
+ break;
+ case PKGMGR_REQ_MOVE:
+ req_cmd = MOVE_CMD;
+ break;
+ case PKGMGR_REQ_SMACK:
+ req_cmd = SMACK_CMD;
+ break;
+ case PKGMGR_REQ_PERM:
+ goto PARSEERROR;
+ case PKGMGR_REQ_INVALID:
+ req_cmd = INVALID_CMD;
+ goto PARSEERROR;
+ default:
+ goto PARSEERROR;
+ }
+ if (req_cmd != RECOVER_CMD) {
+ pkgid = pkgmgr_installer_get_request_info(pi);
+ if (!pkgid) {
+ _d_msg(DEBUG_ERR,
+ "pkgmgr_installer_get_request_info failed \n");
+ return RPM_INSTALLER_ERR_WRONG_PARAM;
+ }
+ pkeyid = pkgmgr_installer_get_session_id(pi);
+ if (!pkeyid) {
+ _d_msg(DEBUG_ERR, "pkgmgr_installer_get_session_id failed \n");
+ return RPM_INSTALLER_ERR_WRONG_PARAM;
+ }
+
+ quiet = pkgmgr_installer_is_quiet(pi);
+ if (quiet != 0 && quiet != 1) {
+ _d_msg(DEBUG_ERR, "pkgmgr_installer_is_quiet failed \n");
+ return RPM_INSTALLER_ERR_WRONG_PARAM;
+ }
+
+ move_type = pkgmgr_installer_get_move_type(pi);
+ }
+ if ((req_cmd < INSTALL_CMD) ||(req_cmd > RPM_CMD_MAX)) {
+ _d_msg(DEBUG_ERR, "invalid command \n");
+ goto PARSEERROR;
+ }
+
+ data->req_cmd = req_cmd;
+ data->pkgid = (char *)pkgid;
+ data->quiet = quiet;
+ data->keyid = (char *)pkeyid;
+ data->move_type = move_type;
+ return RPM_INSTALLER_SUCCESS;
+
+ PARSEERROR:
+ _d_msg(DEBUG_ERR, "Error in parsing input parameter\n");
+ __ri_show_usage(argv);
+ return RPM_INSTALLER_ERR_WRONG_PARAM;
+
+}
+
+static int __ri_process_request(ri_frontend_cmdline_arg *data)
+{
+ int ret = 0;
+ if (!data)
+ return RPM_INSTALLER_ERR_WRONG_PARAM;
+ char *pkgid = NULL;
+ char *keyid = NULL;
+ if (data->req_cmd != RECOVER_CMD) {
+ pkgid = strdup(data->pkgid);
+ if (PM_UNLIKELY(pkgid == NULL)) {
+ _d_msg(DEBUG_ERR, "strdup failed\n");
+ return RPM_INSTALLER_ERR_WRONG_PARAM;
+ }
+ keyid = strdup(data->keyid);
+ if (PM_UNLIKELY(keyid == NULL)) {
+ _d_msg(DEBUG_ERR, "strdup failed\n");
+ free(pkgid);
+ return RPM_INSTALLER_ERR_WRONG_PARAM;
+ }
+ }
+
+ if (pkgid == NULL) {
+ _d_msg(DEBUG_ERR, "pkgid is null\n");
+ return -1;
+ }
+
+ switch (data->req_cmd) {
+ case INSTALL_CMD:
+ _d_msg(DEBUG_INFO, "rpm-backend -i %s\n", pkgid);
+ ret = _rpm_backend_interface(keyid, pkgid, "install");
+ break;
+ case DELETE_CMD:
+ _d_msg(DEBUG_INFO, "rpm-backend -d %s\n", pkgid);
+ ret = _rpm_backend_interface(keyid, pkgid, "remove");
+ break;
+ case CLEARDATA_CMD:
+ _d_msg(DEBUG_INFO, "rpm-backend -c %s\n", pkgid);
+ ret = _rpm_backend_interface(keyid, pkgid, "cleardata");
+ break;
+ case MOVE_CMD:
+ _d_msg(DEBUG_INFO, "rpm-backend -m %s -t %d\n", pkgid, data->move_type);
+ move_type = data->move_type;
+ ret = _rpm_backend_interface(keyid, pkgid, "move");
+ break;
+ case RECOVER_CMD:
+ _d_msg(DEBUG_INFO, "rpm-backend -r \n");
+ ret = _rpm_backend_interface(keyid, pkgid, "recover");
+ break;
+ case SMACK_CMD:
+ _d_msg(DEBUG_INFO, "rpm-backend -s %s\n", pkgid);
+ ret = _rpm_backend_interface(keyid, pkgid, "smack");
+ break;
+ case EFLWGT_INSTALL_CMD:
+ _d_msg(DEBUG_INFO, "eflwgt-install %s\n", pkgid);
+ ret = _rpm_backend_interface(keyid, pkgid, "eflwgt-install");
+ break;
+ case EFLWGT_DELETE_CMD:
+ _d_msg(DEBUG_INFO, "eflwgt-remove %s\n", pkgid);
+ ret = _rpm_backend_interface(keyid, pkgid, "eflwgt-remove");
+ break;
+ case ENABLE_CMD:
+ _d_msg(DEBUG_INFO, "rpm enable %s\n", pkgid);
+ ret = _rpm_backend_interface(keyid, pkgid, "rpm-enable");
+ break;
+ case DISABLE_CMD:
+ _d_msg(DEBUG_INFO, "rpm disable %s\n", pkgid);
+ ret = _rpm_backend_interface(keyid, pkgid, "rpm-disable");
+ break;
+ default:
+ _d_msg(DEBUG_ERR,
+ "Error Never Come Here as Error is already checked\n");
+
+ }
+
+ if (keyid) {
+ free(keyid);
+ keyid = NULL;
+ }
+ if (pkgid) {
+ free(pkgid);
+ pkgid = NULL;
+ }
+
+ return ret;
+}
+
+void _ri_stat_cb(const char *pkgid, const char *key, const char *val)
+{
+
+ if (NULL == pkgid || NULL == key || NULL == val) {
+ _d_msg(DEBUG_ERR, "Either pkgid/key/val is NULL\n");
+ return; /*TODO: handle error. */
+ }
+
+ char *pkgid_modified = NULL;
+ char delims[] = "/";
+ char *result = NULL;
+ char *pkgid_tmp = NULL;
+ char *saveptr = NULL;
+
+ pkgid_modified = (char *)malloc(strlen(pkgid) + 1);
+ if (pkgid_modified == NULL) {
+ _d_msg(DEBUG_ERR, "pkgid_modified is NULL. Malloc failed\n");
+ return;
+ }
+ memset(pkgid_modified, '\0', strlen(pkgid) + 1);
+ memcpy(pkgid_modified, pkgid, strlen(pkgid));
+
+ result = strtok_r(pkgid_modified, delims, &saveptr);
+ while (result != NULL) {
+ pkgid_tmp = result;
+ result = strtok_r(NULL, delims, &saveptr);
+ }
+
+ if (strcmp(key, "install_percent") == 0) {
+ return;
+ } else if (strcmp(key, "error") == 0) {
+ /* Store the error to be display to the user */
+ front_data.error = strdup(val);
+ } else if (strcmp(key, "end") == 0) {
+
+ char requesttype[32];
+ switch (front_data.args->req_cmd) {
+ case INSTALL_CMD:
+ snprintf(requesttype, sizeof(requesttype),
+ _("Installation"));
+ break;
+ case DELETE_CMD:
+ snprintf(requesttype, sizeof(requesttype), _("Deletion"));
+ break;
+ case CLEARDATA_CMD:
+ snprintf(requesttype, sizeof(requesttype),
+ _("Clear Data"));
+ break;
+ case MOVE_CMD:
+ snprintf(requesttype, sizeof(requesttype),
+ _("Move"));
+ break;
+ default:
+ snprintf(requesttype, sizeof(requesttype), _("Recovery"));
+ break;
+ }
+
+ if (front_data.error) {
+ /* Error Happened */
+ snprintf(scrolllabel, sizeof(scrolllabel),
+ "%s :: %s:: %s:: %s", requesttype, pkgid_tmp,
+ "Error",
+ front_data.error);
+ _d_msg(DEBUG_ERR, "%s\n", scrolllabel);
+ ret_val = _ri_string_to_error_no(front_data.error);
+ _d_msg(DEBUG_ERR, "%d\n", ret_val);
+
+ } else {
+ snprintf(scrolllabel, sizeof(scrolllabel),
+ " %s :: %s :: %s", requesttype, pkgid_tmp,
+ "Success");
+ _d_msg(DEBUG_INFO, "%s\n", scrolllabel);
+ ret_val = 0;
+ }
+ }
+}
+
+int _ri_cmdline_process(ri_frontend_data *data)
+{
+ int ret = 0;
+ ri_frontend_cmdline_arg *fdata = data->args;
+ /*rpm-installer is invoked by pkgmgr-server hence server should do cookie validation*/
+ ret = __ri_process_request(fdata);
+ if (ret != RPM_INSTALLER_SUCCESS) {
+ _d_msg(DEBUG_ERR, "__ri_process_request: Error\n");
+ return ret;
+ }
+ return RPM_INSTALLER_SUCCESS;
+}
+
+int _ri_cmdline_destroy(ri_frontend_data *data)
+{
+ if (data == NULL)
+ return 0;
+
+ if (data->security_cookie)
+ free(data->security_cookie);
+
+ return 0;
+
+}
--- /dev/null
+/*
+ * rpm-installer
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
+ * Jaeho Lee <jaeho81.lee@samsung.com>, Shobhit Srivastava <shobhit.s@samsung.com>
+ *
+ * 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.
+ *
+ */
+
+#ifndef HOME_VIEW_H_
+#define HOME_VIEW_H_
+
+void _ri_information_popup(Evas_Smart_Cb func, const char *output,
+ void *user_param);
+void _ri_package_downgrade_popup(Evas_Smart_Cb func1, Evas_Smart_Cb func2, const char *output,
+ void *user_param);
+Eina_Bool _ri_init_appdata(struct appdata *ad);
+Eina_Bool _ri_init_home_view(struct appdata *ad);
+void _ri_destroy_home_view(struct appdata *ad);
+int _ri_frontend_launch_main_view(struct appdata *data);
+void _ri_frontend_update_progress_info(struct appdata *data,
+ char *progressinfo);
+
+#endif /* HOME_VIEW_H_ */
--- /dev/null
+/*
+ * rpm-installer
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
+ * Jaeho Lee <jaeho81.lee@samsung.com>, Shobhit Srivastava <shobhit.s@samsung.com>
+ *
+ * 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 <appcore-efl.h>
+#include <Ecore_X.h>
+#include <pthread.h>
+#include "rpm-frontend.h"
+#include "rpm-installer-util.h"
+#include "rpm-homeview.h"
+#include "rpm-installer.h"
+
+#define DESKTOP_W 720.0
+
+extern struct appdata ad;
+int do_upgrade = -1;
+extern ri_frontend_data front_data;
+Evas_Object *popup_global;
+
+static void __ri_response_cb1(void *data, Evas_Object *obj, void *event);
+static void __ri_response_cb2(void *data, Evas_Object *obj, void *event);
+static void __ri_win_del(void *data, Evas_Object *obj, void *event);
+static Eina_Bool __ri_perform_downgrade(void *data);
+
+void _ri_information_popup(Evas_Smart_Cb func, const char *output,
+ void *user_param)
+{
+ if (!ad.win_main)
+ return;
+ evas_object_show(ad.win_main);
+ Evas_Object *popup = NULL;
+ popup = elm_popup_add(ad.win_main);
+ if (!popup)
+ return;
+ elm_object_part_text_set(popup, "Information", NULL);
+ evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND,
+ EVAS_HINT_EXPAND);
+ elm_object_text_set(popup, output);
+ Evas_Object *button = NULL;
+ button = elm_button_add(popup);
+ elm_object_text_set(button, "Ok");
+ elm_object_part_content_set(popup, "button1", button);
+ evas_object_smart_callback_add(button, "clicked", func, user_param);
+ evas_object_show(popup);
+}
+
+void _ri_package_downgrade_popup(Evas_Smart_Cb func1,
+ Evas_Smart_Cb func2,
+ const char *output, void *user_param)
+{
+ if (!ad.win_main)
+ return;
+ evas_object_show(ad.win_main);
+ Evas_Object *popup = NULL;
+ popup = elm_popup_add(ad.win_main);
+ if (!popup)
+ return;
+ elm_object_part_text_set(popup, "Information", NULL);
+ evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND,
+ EVAS_HINT_EXPAND);
+ elm_object_text_set(popup, output);
+ Evas_Object *button1 = NULL;
+ Evas_Object *button2 = NULL;
+ button1 = elm_button_add(popup);
+ elm_object_text_set(button1, "Yes");
+ elm_object_part_content_set(popup, "button1", button1);
+ evas_object_smart_callback_add(button1, "clicked", func1, user_param);
+
+ button2 = elm_button_add(popup);
+ elm_object_text_set(button2, "No");
+ elm_object_part_content_set(popup, "button2", button2);
+ evas_object_smart_callback_add(button2, "clicked", func2, user_param);
+ popup_global = popup;
+ evas_object_show(popup);
+}
+
+static void __ri_win_del(void *data, Evas_Object *obj, void *event)
+{
+ elm_exit();
+}
+
+static Eina_Bool __ri_perform_downgrade(void *data)
+{
+ int ret = -1;
+ ret = _rpm_installer_package_install(front_data.args->pkgid,
+ true, "--force");
+ if (ret != 0) {
+ char *errstr = NULL;
+ _ri_error_no_to_string(ret, &errstr);
+ _ri_broadcast_status_notification(front_data.args->pkgid,
+ "error", errstr);
+ _ri_stat_cb(front_data.args->pkgid, "error", errstr);
+ _ri_broadcast_status_notification(front_data.args->pkgid,
+ "end", "fail");
+ _ri_stat_cb(front_data.args->pkgid, "end", "fail");
+ _d_msg(DEBUG_ERR,
+ "install failed with err(%d) (%s)\n", ret, errstr);
+ } else {
+ _d_msg(DEBUG_INFO, "install success\n");
+ _ri_broadcast_status_notification(front_data.args->pkgid,
+ "end", "ok");
+ _ri_stat_cb(front_data.args->pkgid, "end", "ok");
+ }
+ _ri_set_backend_state_info(REQUEST_COMPLETED);
+ _ri_set_backend_state(1);
+ return 0;
+}
+
+static void __ri_response_cb1(void *data, Evas_Object *obj, void *event)
+{
+ printf("\nresponse callback=%d\n", (int)event);
+ do_upgrade = 1;
+
+ ecore_idler_add(__ri_perform_downgrade, NULL);
+ _d_msg(DEBUG_INFO, "doUpgrade is %d\n", do_upgrade);
+ evas_object_del(obj);
+ evas_object_del(popup_global);
+ obj = NULL;
+}
+static void __ri_response_cb2(void *data, Evas_Object *obj, void *event)
+{
+ printf("\nresponse callback=%d\n", (int)event);
+ do_upgrade = 0;
+
+ ecore_idler_add(__ri_perform_downgrade, NULL);
+ evas_object_del(obj);
+ evas_object_del(popup_global);
+ _d_msg(DEBUG_INFO, "doUpgrade is %d\n", do_upgrade);
+ obj = NULL;
+}
+
+Eina_Bool _ri_init_appdata(struct appdata *user_data)
+{
+ unsigned char *prop_data = NULL;
+ int rotation = 0;
+ int w;
+ int h;
+ int x;
+ int y;
+ int count = 0;
+ user_data->win_main = elm_win_add(NULL, PACKAGE, ELM_WIN_DIALOG_BASIC);
+ if (!user_data->win_main)
+ return EINA_FALSE;
+
+ elm_win_title_set(user_data->win_main, PACKAGE);
+ elm_win_alpha_set(user_data->win_main, EINA_TRUE);
+ elm_win_borderless_set(user_data->win_main, EINA_TRUE);
+ elm_win_raise(user_data->win_main);
+ ecore_x_window_geometry_get(ecore_x_window_root_get
+ (ecore_x_window_focus_get()), &x, &y, &w,
+ &h);
+ int ret =
+ ecore_x_window_prop_property_get(ecore_x_window_root_get
+ (ecore_x_window_focus_get()),
+ ECORE_X_ATOM_E_ILLUME_ROTATE_ROOT_ANGLE,
+ ECORE_X_ATOM_CARDINAL, 32,
+ &prop_data, &count);
+ if (ret && prop_data)
+ memcpy(&rotation, prop_data, sizeof(int));
+ if (prop_data)
+ free(prop_data);
+ evas_object_resize(user_data->win_main, w, h);
+ evas_object_move(user_data->win_main, x, y);
+ /*evas_object_show(user_data->win_main);
+ evas_object_smart_callback_add(user_data->win_main, "delete,request",
+ __ri_win_del, NULL);
+ elm_win_indicator_state_set(user_data->win_main, EINA_TRUE);*/
+
+ if (elm_win_wm_rotation_supported_get(user_data->win_main)) {
+ int rots[4] = { 0, 90, 180, 270 };
+ elm_win_wm_rotation_available_rotations_set(user_data->win_main, &rots, 4);
+ }
+
+ double s;
+ s = w / DESKTOP_W;
+ elm_config_scale_set(s);
+ user_data->evas = evas_object_evas_get(user_data->win_main);
+ if (!user_data->evas)
+ return EINA_FALSE;
+
+ return EINA_TRUE;
+}
+
+Eina_Bool _ri_init_home_view(struct appdata *user_data)
+{
+ return EINA_TRUE;
+
+}
+
+void _ri_destroy_home_view(struct appdata *user_data)
+{
+
+ if (!user_data) {
+ return;
+ }
+ evas_object_del(user_data->main_view);
+}
+
+int _ri_frontend_launch_main_view(struct appdata *data)
+{
+ /* create UI */
+ if (!_ri_init_appdata(data)) {
+ return 0;
+ }
+ if (!_ri_init_home_view(data)) {
+ return 0;
+ }
+ return 0;
+}
+
+void _ri_frontend_update_progress_info(struct appdata *data, char *progressinfo)
+{
+ elm_object_text_set(data->scrollbar_label, progressinfo);
+ _ri_information_popup(__ri_win_del, progressinfo, data);
+}
+
+void _ri_package_downgrade_information(const char *message)
+{
+ _ri_package_downgrade_popup(__ri_response_cb1, __ri_response_cb2, message, &ad);
+}
--- /dev/null
+/*
+ * rpm-installer
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
+ * Jaeho Lee <jaeho81.lee@samsung.com>, Shobhit Srivastava <shobhit.s@samsung.com>
+ *
+ * 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.
+ *
+ */
+
+#ifndef __RPM_INSTALLER_UTIL_H_
+#define __RPM_INSTALLER_UTIL_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+#include <string.h>
+#include <stdarg.h>
+#include <sys/wait.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <libgen.h>
+#include <wait.h>
+#include <stdio.h>
+
+#include <dlog.h>
+
+#define RPM_BACKEND_EXEC "rpm-backend"
+
+#define PKGTYPE "rpm"
+
+/*Error number according to Tizen Native Package Manager Command Specification v1.0*/
+#define RPM_INSTALLER_SUCCESS 0
+#define RPM_INSTALLER_ERR_WRONG_PARAM 64
+#define RPM_INSTALLER_ERR_DBUS_PROBLEM 102
+#define RPM_INSTALLER_ERR_PACKAGE_EXIST 121
+#define RPM_INSTALLER_ERR_PACKAGE_NOT_INSTALLED 104
+#define RPM_INSTALLER_ERR_RESOURCE_BUSY 105
+#define RPM_INSTALLER_ERR_NOT_ENOUGH_MEMORY 63
+#define RPM_INSTALLER_ERR_NOT_SUPPOTED_VERSION 107
+#define RPM_INSTALLER_ERR_NO_RPM_FILE 2
+#define RPM_INSTALLER_ERR_DB_ACCESS_FAILED 109
+#define RPM_INSTALLER_ERR_RPM_OPERATION_FAILED 110
+#define RPM_INSTALLER_ERR_PACKAGE_NOT_UPGRADED 111
+#define RPM_INSTALLER_ERR_RPM_SCRIPT_WRONG_ARGS 112
+#define RPM_INSTALLER_ERR_NEED_USER_CONFIRMATION 113
+#define RPM_INSTALLER_ERR_PACKAGE_INSTALLATION_DISABLED 114
+#define RPM_INSTALLER_ERR_PACKAGE_UNINSTALLATION_DISABLED 115
+#define RPM_INSTALLER_ERR_CLEAR_DATA_FAILED 116
+#define RPM_INSTALLER_ERR_INTERNAL 117
+#define RPM_INSTALLER_ERR_PKG_NOT_FOUND 1
+#define RPM_INSTALLER_ERR_UNKNOWN 119
+#define RPM_INSTALLER_ERR_NO_MANIFEST 11
+#define RPM_INSTALLER_ERR_INVALID_MANIFEST 12
+#define RPM_INSTALLER_ERR_SIG_NOT_FOUND 21
+#define RPM_INSTALLER_ERR_SIG_INVALID 22
+#define RPM_INSTALLER_ERR_SIG_VERIFICATION_FAILED 23
+#define RPM_INSTALLER_ERR_ROOT_CERT_NOT_FOUND 31
+#define RPM_INSTALLER_ERR_CERT_INVALID 32
+#define RPM_INSTALLER_ERR_CERTCHAIN_VERIFICATION_FAILED 33
+
+#define RPM_INSTALLER_SUCCESS_STR "Success"
+#define RPM_INSTALLER_ERR_WRONG_PARAM_STR "Wrong Input Param"
+#define RPM_INSTALLER_ERR_DBUS_PROBLEM_STR "DBUS Error"
+#define RPM_INSTALLER_ERR_NOT_ENOUGH_MEMORY_STR "Not Enough Memory"
+#define RPM_INSTALLER_ERR_PACKAGE_EXIST_STR "Package Already Installed"
+#define RPM_INSTALLER_ERR_PACKAGE_NOT_INSTALLED_STR "Package Not Installed"
+#define RPM_INSTALLER_ERR_RESOURCE_BUSY_STR "Resource Busy"
+#define RPM_INSTALLER_ERR_UNKNOWN_STR "Unknown Error"
+#define RPM_INSTALLER_ERR_PKG_NOT_FOUND_STR "Package file not found"
+#define RPM_INSTALLER_ERR_NOT_SUPPOTED_VERSION_STR "Version Not supported"
+#define RPM_INSTALLER_ERR_NO_RPM_FILE_STR "No RPM Package"
+#define RPM_INSTALLER_ERR_DB_ACCESS_FAILED_STR "DB Access Failed"
+#define RPM_INSTALLER_ERR_RPM_OPERATION_FAILED_STR "RPM operation failed"
+#define RPM_INSTALLER_ERR_PACKAGE_NOT_UPGRADED_STR "Package Not Upgraded"
+#define RPM_INSTALLER_ERR_RPM_SCRIPT_WRONG_ARGS_STR "Wrong Args to Script"
+#define RPM_INSTALLER_ERR_PACKAGE_INSTALLATION_DISABLED_STR "Installation Disabled"
+#define RPM_INSTALLER_ERR_PACKAGE_UNINSTALLATION_DISABLED_STR "Uninstallation Disabled"
+#define RPM_INSTALLER_ERR_CLEAR_DATA_FAILED_STR "Clear Data Failed"
+#define RPM_INSTALLER_ERR_INTERNAL_STR "Internal Error"
+#define RPM_INSTALLER_ERR_NO_MANIFEST_STR "Manifest File Not Found"
+#define RPM_INSTALLER_ERR_INVALID_MANIFEST_STR "Manifest Validation Failed"
+#define RPM_INSTALLER_ERR_SIG_NOT_FOUND_STR "Signature Not Found"
+#define RPM_INSTALLER_ERR_SIG_INVALID_STR "Invalid Signature"
+#define RPM_INSTALLER_ERR_SIG_VERIFICATION_FAILED_STR "Signature Verification Failed"
+#define RPM_INSTALLER_ERR_ROOT_CERT_NOT_FOUND_STR "Root Cert Not Found"
+#define RPM_INSTALLER_ERR_CERT_INVALID_STR "Invalid Certificate"
+#define RPM_INSTALLER_ERR_CERTCHAIN_VERIFICATION_FAILED_STR "Certificate Chain Verification Failed"
+
+#define DEBUG_ERR 0x0001
+#define DEBUG_INFO 0x0002
+#define DEBUG_RESULT 0x0004
+
+#define RPM_LOG 1
+
+void _print_msg(int type, int exetype, char *format, ...);
+
+#define _d_msg(type, fmtstr, args...) { \
+_print_msg(0x0001, RPM_LOG, "%s:%d:%s(): " fmtstr, basename(__FILE__), \
+__LINE__, __func__, ##args); \
+}
+
+ void _d_msg_init(char *program);
+ void _d_msg_deinit();
+ void _ri_error_no_to_string(int errnumber, char **errstr);
+ int _ri_string_to_error_no(char *errstr);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+#endif /* __RPM_INSTALLER_UTIL_H_ */
--- /dev/null
+Name: rpm-installer
+Summary: Native rpm installer
+Version: 0.1.68
+Release: 1
+Group: System/Libraries
+License: Apache License, Version 2.0
+Source0: %{name}-%{version}.tar.gz
+Requires(post): /sbin/ldconfig
+Requires(postun): /sbin/ldconfig
+BuildRequires: cmake
+BuildRequires: edje-bin
+BuildRequires: rpm-devel
+BuildRequires: popt-devel
+BuildRequires: pkgconfig(glib-2.0)
+BuildRequires: pkgconfig(dbus-glib-1)
+BuildRequires: pkgconfig(sqlite3)
+BuildRequires: pkgconfig(dlog)
+BuildRequires: pkgconfig(vconf)
+BuildRequires: pkgconfig(db-util)
+BuildRequires: pkgconfig(pkgmgr-types)
+BuildRequires: pkgconfig(pkgmgr-installer)
+BuildRequires: pkgconfig(pkgmgr-parser)
+BuildRequires: pkgconfig(pkgmgr)
+BuildRequires: pkgconfig(pkgmgr-info)
+BuildRequires: pkgconfig(app2sd)
+BuildRequires: pkgconfig(libxml-2.0)
+BuildRequires: pkgconfig(security-server)
+BuildRequires: pkgconfig(elementary)
+BuildRequires: pkgconfig(appcore-efl)
+BuildRequires: pkgconfig(cert-svc)
+BuildRequires: pkgconfig(xmlsec1)
+BuildRequires: pkgconfig(libxslt)
+BuildRequires: pkgconfig(evas)
+BuildRequires: pkgconfig(ecore)
+BuildRequires: pkgconfig(edje)
+BuildRequires: pkgconfig(libprivilege-control)
+BuildRequires: pkgconfig(capi-appfw-app-manager)
+BuildRequires: pkgconfig(aul)
+BuildRequires: gettext-tools
+Requires: /bin/cpio
+
+%description
+Native rpm installer
+
+%prep
+%setup -q
+
+%build
+CFLAGS+=" -fpic"
+
+%if 0%{?tizen_build_binary_release_type_eng}
+export CFLAGS="$CFLAGS -DTIZEN_ENGINEER_MODE"
+export CXXFLAGS="$CXXFLAGS ?DTIZEN_ENGINEER_MODE"
+export FFLAGS="$FFLAGS -DTIZEN_ENGINEER_MODE"
+%endif
+
+cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix}
+
+make %{?jobs:-j%jobs}
+
+%install
+rm -rf %{buildroot}
+%make_install
+
+mkdir -p %{buildroot}/usr/share/license
+cp LICENSE %{buildroot}/usr/share/license/%{name}
+
+%post
+mkdir -p /usr/etc/package-manager/backend
+mkdir -p /usr/etc/package-manager/backendlib
+mkdir -p /opt/share/packages/.pkgmgr/rpm-installer/
+
+ln -sf /usr/bin/rpm-backend /usr/etc/package-manager/backend/rpm
+ln -sf /usr/lib/libnativerpm.so /usr/etc/package-manager/backendlib/librpm.so
+
+chmod 700 /usr/bin/rpm-backend
+
+vconftool set -t int db/private/rpm-installer/state "0" -f -s system::vconf_inhouse
+vconftool set -t int db/private/rpm-installer/stateinfo "0" -f -s system::vconf_inhouse
+vconftool set -t int db/private/rpm-installer/requestinfo/command "0" -f -s system::vconf_inhouse
+vconftool set -t string db/private/rpm-installer/requestinfo/pkgname "" -f -s system::vconf_inhouse
+vconftool set -t int db/private/rpm-installer/requestinfo/options "0" -f -s system::vconf_inhouse
+
+%files
+%manifest rpm-installer.manifest
+%attr(0700,-,-) /usr/bin/rpm-backend
+%attr(0700,-,-) /usr/bin/install_rpm_package.sh
+%attr(0700,-,-) /usr/bin/install_rpm_package_with_dbpath_ro.sh
+%attr(0700,-,-) /usr/bin/install_rpm_package_with_dbpath_rw.sh
+%attr(0755,-,-) /usr/bin/query_rpm_package.sh
+%attr(0700,-,-) /usr/bin/uninstall_rpm_package.sh
+%attr(0700,-,-) /usr/bin/upgrade_rpm_package.sh
+%attr(0700,-,-) /usr/bin/upgrade_rpm_package_with_dbpath_ro.sh
+%attr(0700,-,-) /usr/bin/upgrade_rpm_package_with_dbpath_rw.sh
+%attr(0700,-,-) /usr/bin/cpio_rpm_package.sh
+%attr(0700,-,-) /usr/bin/cpio_rpm_package_update_xml.sh
+%attr(0700,-,-) /usr/bin/post_script_rpm.sh
+%attr(0744,-,-) /usr/etc/rpm-installer-config.ini
+%attr(0644,-,-) /usr/share/locale/en_GB/LC_MESSAGES/rpm-installer.mo
+%attr(0644,-,-) /usr/share/locale/ja_JP/LC_MESSAGES/rpm-installer.mo
+%attr(0644,-,-) /usr/share/locale/zh_CN/LC_MESSAGES/rpm-installer.mo
+%attr(0644,-,-) /usr/share/locale/en_US/LC_MESSAGES/rpm-installer.mo
+%attr(0644,-,-) /usr/share/locale/ko_KR/LC_MESSAGES/rpm-installer.mo
+%attr(0644,-,-) /usr/lib/libnativerpm.so
+%attr(0755,-,-) /opt/share/packages/.pkgmgr/rpm-installer/rpm_installer_deactvation_list.txt
+/usr/share/license/%{name}
+
--- /dev/null
+# for i18n
+
+SET(POFILES en_US.po en_GB.po ja_JP.po ko_KR.po zh_CN.po)
+
+SET(MSGFMT "/usr/bin/msgfmt")
+
+FOREACH(pofile ${POFILES})
+ SET(pofile ${CMAKE_CURRENT_SOURCE_DIR}/${pofile})
+ MESSAGE("PO: ${pofile}")
+ GET_FILENAME_COMPONENT(absPofile ${pofile} ABSOLUTE)
+ GET_FILENAME_COMPONENT(lang ${absPofile} NAME_WE)
+ SET(moFile ${CMAKE_CURRENT_BINARY_DIR}/${lang}.mo)
+ ADD_CUSTOM_COMMAND(
+ OUTPUT ${moFile}
+ COMMAND ${MSGFMT} -o ${moFile} ${absPofile}
+ DEPENDS ${absPofile}
+ )
+ INSTALL(FILES ${moFile}
+ DESTINATION share/locale/${lang}/LC_MESSAGES RENAME ${PROJECT_NAME}.mo)
+ SET(moFiles ${moFiles} ${moFile})
+ENDFOREACH(pofile)
+
+MESSAGE(".mo files: ${moFiles}")
+ADD_CUSTOM_TARGET(po ALL DEPENDS ${moFiles})
--- /dev/null
+# List of source files containing translatable strings.
+frontend/src/rpm-cmdline.c
+frontend/src/rpm-appcore-intf.c
--- /dev/null
+# SOME DESCRIPTIVE TITLE.
+# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
+# This file is distributed under the same license as the PACKAGE package.
+# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2012-01-03 15:32+0900\n"
+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
+"Language-Team: LANGUAGE <LL@li.org>\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+#: frontend/src/rpm-appcore-intf.c:129
+#, c-format
+msgid "Continue Downgrade?"
+msgstr ""
+
+#: frontend/src/rpm-cmdline.c:245
+#, c-format
+msgid "Installation"
+msgstr ""
+
+#: frontend/src/rpm-cmdline.c:248
+#, c-format
+msgid "Deletion"
+msgstr ""
+
+#: frontend/src/rpm-cmdline.c:255
+#, c-format
+msgid "Recovery"
+msgstr ""
+
+#: frontend/src/rpm-cmdline.c:252
+#, c-format
+msgid "Clear Data"
+msgstr ""
--- /dev/null
+# SOME DESCRIPTIVE TITLE.
+# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
+# This file is distributed under the same license as the PACKAGE package.
+# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2012-01-03 15:32+0900\n"
+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
+"Language-Team: LANGUAGE <LL@li.org>\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+#: frontend/src/rpm-appcore-intf.c:129
+#, c-format
+msgid "Continue Downgrade?"
+msgstr ""
+
+#: frontend/src/rpm-cmdline.c:245
+#, c-format
+msgid "Installation"
+msgstr ""
+
+#: frontend/src/rpm-cmdline.c:248
+#, c-format
+msgid "Deletion"
+msgstr ""
+
+#: frontend/src/rpm-cmdline.c:255
+#, c-format
+msgid "Recovery"
+msgstr ""
+
+#: frontend/src/rpm-cmdline.c:252
+#, c-format
+msgid "Clear Data"
+msgstr ""
--- /dev/null
+# SOME DESCRIPTIVE TITLE.
+# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
+# This file is distributed under the same license as the PACKAGE package.
+# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2012-01-03 15:32+0900\n"
+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
+"Language-Team: LANGUAGE <LL@li.org>\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+#: frontend/src/rpm-appcore-intf.c:129
+#, c-format
+msgid "Continue Downgrade?"
+msgstr "ダウングレード を続行しますか?"
+
+#: frontend/src/rpm-cmdline.c:245
+#, c-format
+msgid "Installation"
+msgstr "インストール"
+
+#: frontend/src/rpm-cmdline.c:248
+#, c-format
+msgid "Deletion"
+msgstr "削除"
+
+#: frontend/src/rpm-cmdline.c:255
+#, c-format
+msgid "Recovery"
+msgstr "回復"
+
+#: frontend/src/rpm-cmdline.c:252
+#, c-format
+msgid "Clear Data"
+msgstr "明確な データ"
--- /dev/null
+# SOME DESCRIPTIVE TITLE.
+# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
+# This file is distributed under the same license as the PACKAGE package.
+# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2012-01-03 15:32+0900\n"
+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
+"Language-Team: LANGUAGE <LL@li.org>\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+#: frontend/src/rpm-appcore-intf.c:129
+#, c-format
+msgid "Continue Downgrade?"
+msgstr "다운 그레이드 를 계속하시겠습니까?"
+
+#: frontend/src/rpm-cmdline.c:245
+#, c-format
+msgid "Installation"
+msgstr "설치"
+
+#: frontend/src/rpm-cmdline.c:248
+#, c-format
+msgid "Deletion"
+msgstr "삭제"
+
+#: frontend/src/rpm-cmdline.c:255
+#, c-format
+msgid "Recovery"
+msgstr "회복"
+
+#: frontend/src/rpm-cmdline.c:252
+#, c-format
+msgid "Clear Data"
+msgstr "삭제 데이터"
--- /dev/null
+#!/bin/sh
+
+PACKAGE=rpm-installer
+SRCROOT=..
+POTFILES=POTFILES.in
+
+#ALL_LINGUAS= am az be ca cs da de el en_CA en_GB es et fi fr hr hu it ja ko lv mk ml ms nb ne nl pa pl pt pt_BR ru rw sk sl sr sr@Latn sv ta tr uk vi zh_CN zh_TW
+ALL_LINGUAS="en_US en_GB ja_JP ko_KR zh_CN"
+
+XGETTEXT=/usr/bin/xgettext
+MSGMERGE=/usr/bin/msgmerge
+
+echo -n "Make ${PACKAGE}.pot "
+if [ ! -e $POTFILES ] ; then
+ echo "$POTFILES not found"
+ exit 1
+fi
+
+$XGETTEXT --default-domain=${PACKAGE} --directory=${SRCROOT} \
+ --add-comments --keyword=_ --keyword=N_ --files-from=$POTFILES
+if [ $? -ne 0 ]; then
+ echo "xgettext error"
+ exit 1
+fi
+
+if [ ! -f ${PACKAGE}.po ]; then
+ echo "No such file: ${PACKAGE}.po"
+ exit 1
+fi
+
+rm -f ${PACKAGE}.pot && mv ${PACKAGE}.po ${PACKAGE}.pot
+echo "done"
+
+for LANG in $ALL_LINGUAS; do
+ echo "$LANG : "
+
+ if [ ! -e $LANG.po ] ; then
+ sed 's/CHARSET/UTF-8/g' ${PACKAGE}.pot > ${LANG}.po
+ echo "${LANG}.po created"
+ else
+ if $MSGMERGE ${LANG}.po ${PACKAGE}.pot -o ${LANG}.new.po ; then
+ if cmp ${LANG}.po ${LANG}.new.po > /dev/null 2>&1; then
+ rm -f ${LANG}.new.po
+ else
+ if mv -f ${LANG}.new.po ${LANG}.po; then
+ echo ""
+ else
+ echo "msgmerge for $LANG.po failed: cannot move $LANG.new.po to $LANG.po" 1>&2
+ rm -f ${LANG}.new.po
+ exit 1
+ fi
+ fi
+ else
+ echo "msgmerge for $LANG failed!"
+ rm -f ${LANG}.new.po
+ fi
+ fi
+ echo ""
+done
--- /dev/null
+# SOME DESCRIPTIVE TITLE.
+# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
+# This file is distributed under the same license as the PACKAGE package.
+# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2012-01-03 15:32+0900\n"
+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
+"Language-Team: LANGUAGE <LL@li.org>\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+#: frontend/src/rpm-appcore-intf.c:129
+#, c-format
+msgid "Continue Downgrade?"
+msgstr "繼續 降級?"
+
+#: frontend/src/rpm-cmdline.c:245
+#, c-format
+msgid "Installation"
+msgstr "安裝"
+
+#: frontend/src/rpm-cmdline.c:248
+#, c-format
+msgid "Deletion"
+msgstr "刪除"
+
+#: frontend/src/rpm-cmdline.c:255
+#, c-format
+msgid "Recovery"
+msgstr "恢復"
+
+#: frontend/src/rpm-cmdline.c:252
+#, c-format
+msgid "Clear Data"
+msgstr "清除數據"
--- /dev/null
+<manifest>
+ <request>
+ <domain name="_"/>
+ </request>
+ <assign>
+ <filesystem path="/usr/bin/install_rpm_package.sh" label="_" exec_label="none"/>
+ <filesystem path="/usr/bin/install_rpm_package_with_dbpath_ro.sh" label="_" exec_label="none"/>
+ <filesystem path="/usr/bin/install_rpm_package_with_dbpath_rw.sh" label="_" exec_label="none"/>
+ <filesystem path="/usr/bin/query_rpm_package.sh" label="_" exec_label="none"/>
+ <filesystem path="/usr/bin/rpm-backend" label="_" exec_label="none"/>
+ <filesystem path="/usr/bin/uninstall_rpm_package.sh" label="_" exec_label="none"/>
+ <filesystem path="/usr/bin/upgrade_rpm_package.sh" label="_" exec_label="none"/>
+ <filesystem path="/usr/bin/upgrade_rpm_package_with_dbpath_ro.sh" label="_" exec_label="none"/>
+ <filesystem path="/usr/bin/upgrade_rpm_package_with_dbpath_rw.sh" label="_" exec_label="none"/>
+ <filesystem path="/usr/bin/cpio_rpm_package.sh" label="_" exec_label="none"/>
+ <filesystem path="/usr/bin/cpio_rpm_package_update_xml.sh" label="_" exec_label="none"/>
+ </assign>
+</manifest>
--- /dev/null
+pkgid=com.samsung.joyn-chat:state=off:
+pkgid=com.samsung.joyn-share:state=off:
\ No newline at end of file