From 4e2567ece46d9dcb1322993e73da0d68020b5cf7 Mon Sep 17 00:00:00 2001 From: Junghyun Yeon Date: Tue, 23 Aug 2016 14:36:56 +0900 Subject: [PATCH 01/16] Implement CSR checking routine Change-Id: Ida96780aef166ab47f3c9cd7f6f4212896923d8d Signed-off-by: Junghyun Yeon --- CMakeLists.txt | 1 + packaging/pkgmgr-server.spec | 1 + src/pkgmgr-server.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index accc292..ac0deb3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -42,6 +42,7 @@ pkg_check_modules(SERVER_DEPS REQUIRED libgum sqlite3 pkgmgr + csr pkgmgr-installer) FOREACH(SERVER_FLAGS ${SERVER_DEPS_CFLAGS}) SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${SERVER_FLAGS}") diff --git a/packaging/pkgmgr-server.spec b/packaging/pkgmgr-server.spec index e2448fa..65ebcb1 100644 --- a/packaging/pkgmgr-server.spec +++ b/packaging/pkgmgr-server.spec @@ -25,6 +25,7 @@ BuildRequires: pkgconfig(pkgmgr-installer) BuildRequires: pkgconfig(drm-service-core-tizen) BuildRequires: pkgconfig(libgum) BuildRequires: pkgconfig(sqlite3) +BuildRequires: pkgconfig(csr) BuildRequires: pkgmgr-info-parser-devel BuildRequires: pkgmgr-info-parser BuildRequires: fdupes diff --git a/src/pkgmgr-server.c b/src/pkgmgr-server.c index 22d15a8..1caa7d1 100644 --- a/src/pkgmgr-server.c +++ b/src/pkgmgr-server.c @@ -42,6 +42,7 @@ #include #include #include +#include #include "pkgmgr_installer.h" #include "pkgmgr-server.h" @@ -410,6 +411,35 @@ static int __pkgcmd_find_pid_by_cmdline(const char *dname, return pid; } +static int __check_csr(backend_info *ptr) +{ + csr_cs_context_h context = NULL; + csr_cs_malware_h detected = NULL; + int ret = -1; + + ret = csr_cs_context_create(&context); + if (ret != CSR_ERROR_NONE) { + ERR("Failed to create csr context"); + return -1; + } + + if (context) { + ret = csr_cs_scan_file(context, ptr->pkgid, &detected); + if (ret != CSR_ERROR_NONE) { + ERR("Failed to scan file[%d]", ret); + return -1; + } + + csr_cs_context_destroy(context); + if (detected != NULL) { + ERR("CSR Denied[%s] Installation", ptr->pkgid); + return -1; + } + } + + return 0; +} + static int __pkgcmd_proc_iter_kill_cmdline(const char *apppath, int option) { DIR *dp; @@ -1427,6 +1457,17 @@ gboolean queue_job(void *data) ptr->req_type = item->req_type; DBG("handle request type [%d]", item->req_type); + if (item->req_type == PKGMGR_REQUEST_TYPE_INSTALL || + item->req_type == PKGMGR_REQUEST_TYPE_MOUNT_INSTALL || + item->req_type == PKGMGR_REQUEST_TYPE_REINSTALL) { + ret = __check_csr(ptr); + if (ret != 0) { + ret = -1; + __send_fail_signal(ptr); + goto end; + } + } + switch (item->req_type) { case PKGMGR_REQUEST_TYPE_INSTALL: __set_backend_busy(x); @@ -1513,6 +1554,7 @@ gboolean queue_job(void *data) break; } +end: ptr->pid = ret; free(item); -- 2.7.4 From 0f06dba4ce99b3e89590c470232a279eccfab228 Mon Sep 17 00:00:00 2001 From: Junghyun Yeon Date: Tue, 30 Aug 2016 09:58:19 +0900 Subject: [PATCH 02/16] Fix CSR routine to not to fail installation when engine is not exists Change-Id: I485108d8d62c5f1029bf646f6e73dda263f00a78 Signed-off-by: Junghyun Yeon --- src/pkgmgr-server.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/pkgmgr-server.c b/src/pkgmgr-server.c index 1caa7d1..021b327 100644 --- a/src/pkgmgr-server.c +++ b/src/pkgmgr-server.c @@ -417,7 +417,7 @@ static int __check_csr(backend_info *ptr) csr_cs_malware_h detected = NULL; int ret = -1; - ret = csr_cs_context_create(&context); + ret = csr_cs_context_create(&context); if (ret != CSR_ERROR_NONE) { ERR("Failed to create csr context"); return -1; @@ -425,10 +425,7 @@ static int __check_csr(backend_info *ptr) if (context) { ret = csr_cs_scan_file(context, ptr->pkgid, &detected); - if (ret != CSR_ERROR_NONE) { - ERR("Failed to scan file[%d]", ret); - return -1; - } + DBG("CSR result[%d]", ret); csr_cs_context_destroy(context); if (detected != NULL) { -- 2.7.4 From 4874b9682f11cf4c32c22a077e9a5cbfd8466a42 Mon Sep 17 00:00:00 2001 From: Junghyun Yeon Date: Wed, 7 Sep 2016 19:18:07 +0900 Subject: [PATCH 03/16] remove csr routines in tv profile Change-Id: I0487e36776f510deb317cd80ee59d6c55fa4d764 Signed-off-by: Junghyun Yeon --- CMakeLists.txt | 23 +++++++++++------------ packaging/pkgmgr-server.spec | 14 ++++++++++++-- src/pkgmgr-server.c | 6 ++++++ 3 files changed, 29 insertions(+), 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ac0deb3..e4f7683 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,22 +32,21 @@ SET(SRCS src/restriction_mode.c ) -pkg_check_modules(SERVER_DEPS REQUIRED - gio-2.0 - dlog - pkgmgr-parser - pkgmgr-info - libtzplatform-config - drm-service-core-tizen - libgum - sqlite3 - pkgmgr - csr - pkgmgr-installer) +SET(SERVER_CHECK_MODULES gio-2.0 dlog pkgmgr-parser pkgmgr-info libtzplatform-config drm-service-core-tizen libgum sqlite3 pkgmgr pkgmgr-installer) +IF(TIZEN_FEATURE_CSR) + pkg_check_modules(SERVER_DEPS REQUIRED ${SERVER_CHECK_MODULES} csr) +ELSE(TIZEN_FEATURE_CSR) + pkg_check_modules(SERVER_DEPS REQUIRED ${SERVER_CHECK_MODULES}) +ENDIF(TIZEN_FEATURE_CSR) + FOREACH(SERVER_FLAGS ${SERVER_DEPS_CFLAGS}) SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${SERVER_FLAGS}") ENDFOREACH(SERVER_FLAGS) +IF(TIZEN_FEATURE_CSR) + ADD_DEFINITIONS("-DTIZEN_FEATURE_CSR") +ENDIF(TIZEN_FEATURE_CSR) + ADD_EXECUTABLE(${PKGMGR_SERVER} ${SRCS}) TARGET_LINK_LIBRARIES(${PKGMGR_SERVER} pkgmgr_installer) TARGET_LINK_LIBRARIES(${PKGMGR_SERVER} ${SERVER_DEPS_LDFLAGS}) diff --git a/packaging/pkgmgr-server.spec b/packaging/pkgmgr-server.spec index 65ebcb1..49f81b1 100644 --- a/packaging/pkgmgr-server.spec +++ b/packaging/pkgmgr-server.spec @@ -25,11 +25,14 @@ BuildRequires: pkgconfig(pkgmgr-installer) BuildRequires: pkgconfig(drm-service-core-tizen) BuildRequires: pkgconfig(libgum) BuildRequires: pkgconfig(sqlite3) -BuildRequires: pkgconfig(csr) BuildRequires: pkgmgr-info-parser-devel BuildRequires: pkgmgr-info-parser BuildRequires: fdupes +%if "%{?profile}" != "tv" +BuildRequires: pkgconfig(csr) +%endif + %description Packager Manager server package for packaging @@ -44,10 +47,17 @@ cp %{SOURCE1001} . %build sqlite3 restriction.db < ./restriction.sql +%if "%{?profile}" != "tv" +_TIZEN_FEATURE_CSR=ON +%else +_TIZEN_FEATURE_CSR=OFF +%endif + %cmake . -DRUN_DIR=%{run_dir} \ -DDB_DIR=%{db_dir} \ -DBACKEND_DIR=%{backend_dir} \ - -DUNITDIR=%{_unitdir} + -DUNITDIR=%{_unitdir} \ + -DTIZEN_FEATURE_CSR:BOOL=${_TIZEN_FEATURE_CSR} %__make %{?_smp_mflags} diff --git a/src/pkgmgr-server.c b/src/pkgmgr-server.c index 021b327..15cd72c 100644 --- a/src/pkgmgr-server.c +++ b/src/pkgmgr-server.c @@ -42,7 +42,9 @@ #include #include #include +#ifdef TIZEN_FEATURE_CSR #include +#endif #include "pkgmgr_installer.h" #include "pkgmgr-server.h" @@ -411,6 +413,7 @@ static int __pkgcmd_find_pid_by_cmdline(const char *dname, return pid; } +#ifdef TIZEN_FEATURE_CSR static int __check_csr(backend_info *ptr) { csr_cs_context_h context = NULL; @@ -436,6 +439,7 @@ static int __check_csr(backend_info *ptr) return 0; } +#endif static int __pkgcmd_proc_iter_kill_cmdline(const char *apppath, int option) { @@ -1454,6 +1458,7 @@ gboolean queue_job(void *data) ptr->req_type = item->req_type; DBG("handle request type [%d]", item->req_type); +#ifdef TIZEN_FEATURE_CSR if (item->req_type == PKGMGR_REQUEST_TYPE_INSTALL || item->req_type == PKGMGR_REQUEST_TYPE_MOUNT_INSTALL || item->req_type == PKGMGR_REQUEST_TYPE_REINSTALL) { @@ -1464,6 +1469,7 @@ gboolean queue_job(void *data) goto end; } } +#endif switch (item->req_type) { case PKGMGR_REQUEST_TYPE_INSTALL: -- 2.7.4 From 7a2b123502d1a5e36bed7ff0ac96fc394a1586c0 Mon Sep 17 00:00:00 2001 From: Junghyun Yeon Date: Wed, 7 Sep 2016 19:40:15 +0900 Subject: [PATCH 04/16] fix cmakelist Change-Id: Iedb7a27594e8b2bf2e354f1dce32acbbfd20b701 Signed-off-by: Junghyun Yeon --- CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e4f7683..aab4587 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,11 +34,11 @@ SET(SRCS SET(SERVER_CHECK_MODULES gio-2.0 dlog pkgmgr-parser pkgmgr-info libtzplatform-config drm-service-core-tizen libgum sqlite3 pkgmgr pkgmgr-installer) IF(TIZEN_FEATURE_CSR) - pkg_check_modules(SERVER_DEPS REQUIRED ${SERVER_CHECK_MODULES} csr) -ELSE(TIZEN_FEATURE_CSR) - pkg_check_modules(SERVER_DEPS REQUIRED ${SERVER_CHECK_MODULES}) + SET(SERVER_CHECK_MODULES "${SERVER_CHECK_MODULES} csr") ENDIF(TIZEN_FEATURE_CSR) +pkg_check_modules(SERVER_DEPS REQUIRED ${SERVER_CHECK_MODULES}) + FOREACH(SERVER_FLAGS ${SERVER_DEPS_CFLAGS}) SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${SERVER_FLAGS}") ENDFOREACH(SERVER_FLAGS) -- 2.7.4 From 02a73649f87abaa63b6ad893d3ea305ef5fa8770 Mon Sep 17 00:00:00 2001 From: Sangyoon Jang Date: Tue, 13 Sep 2016 10:18:54 +0900 Subject: [PATCH 05/16] Fix sending app signal Send to signal agent too. Change-Id: Ifa2229c35ef5c9ce92938885892f2b78e3f65c52 Signed-off-by: Sangyoon Jang --- CMakeLists.txt | 3 +- include/pkgmgr-server.h | 4 ++ packaging/pkgmgr-server.spec | 1 + src/pkgmgr-server.c | 84 ---------------------- src/signal.c | 166 +++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 173 insertions(+), 85 deletions(-) create mode 100644 src/signal.c diff --git a/CMakeLists.txt b/CMakeLists.txt index aab4587..3abb01a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,9 +30,10 @@ SET(SRCS src/request.c src/pm-queue.c src/restriction_mode.c + src/signal.c ) -SET(SERVER_CHECK_MODULES gio-2.0 dlog pkgmgr-parser pkgmgr-info libtzplatform-config drm-service-core-tizen libgum sqlite3 pkgmgr pkgmgr-installer) +SET(SERVER_CHECK_MODULES gio-2.0 dlog pkgmgr-parser pkgmgr-info libtzplatform-config drm-service-core-tizen libgum sqlite3 pkgmgr pkgmgr-installer libsystemd) IF(TIZEN_FEATURE_CSR) SET(SERVER_CHECK_MODULES "${SERVER_CHECK_MODULES} csr") ENDIF(TIZEN_FEATURE_CSR) diff --git a/include/pkgmgr-server.h b/include/pkgmgr-server.h index 0c8b9dc..13efc58 100644 --- a/include/pkgmgr-server.h +++ b/include/pkgmgr-server.h @@ -109,6 +109,10 @@ gboolean queue_job(void *data); int __return_value_to_caller(const char *req_key, GVariant *result); int __init_request_handler(void); void __fini_request_handler(void); +void __send_app_signal(uid_t uid, const char *req_id, + const char *pkgid, const char *appid, + const char *key, const char *val, int req_type); +void __send_fail_signal(backend_info *info); int _restriction_mode_set(uid_t uid, const char *pkgid, int mode); int _restriction_mode_unset(uid_t uid, const char *pkgid, int mode); int _restriction_mode_get(uid_t uid, const char *pkgid, int *mode); diff --git a/packaging/pkgmgr-server.spec b/packaging/pkgmgr-server.spec index 49f81b1..dbb360f 100644 --- a/packaging/pkgmgr-server.spec +++ b/packaging/pkgmgr-server.spec @@ -25,6 +25,7 @@ BuildRequires: pkgconfig(pkgmgr-installer) BuildRequires: pkgconfig(drm-service-core-tizen) BuildRequires: pkgconfig(libgum) BuildRequires: pkgconfig(sqlite3) +BuildRequires: pkgconfig(libsystemd) BuildRequires: pkgmgr-info-parser-devel BuildRequires: pkgmgr-info-parser BuildRequires: fdupes diff --git a/src/pkgmgr-server.c b/src/pkgmgr-server.c index 15cd72c..061c2b8 100644 --- a/src/pkgmgr-server.c +++ b/src/pkgmgr-server.c @@ -133,90 +133,6 @@ static void __set_backend_free(int position) backend_busy = backend_busy & ~(1<req_id); - switch (info->req_type) { - case PKGMGR_REQUEST_TYPE_INSTALL: - case PKGMGR_REQUEST_TYPE_MOUNT_INSTALL: - case PKGMGR_REQUEST_TYPE_REINSTALL: - req_type = PKGMGR_REQ_INSTALL; - break; - case PKGMGR_REQUEST_TYPE_UNINSTALL: - req_type = PKGMGR_REQ_UNINSTALL; - break; - case PKGMGR_REQUEST_TYPE_MOVE: - req_type = PKGMGR_REQ_MOVE; - break; - case PKGMGR_REQUEST_TYPE_GETSIZE: - req_type = PKGMGR_REQ_GETSIZE; - break; - default: - req_type = PKGMGR_REQ_INVALID; - break; - } - pkgmgr_installer_set_request_type(pi, req_type); - pkgmgr_installer_send_signal(pi, info->pkgtype, info->pkgid, "end", "fail"); - pkgmgr_installer_free(pi); - return; -} - static gboolean pipe_io_handler(GIOChannel *io, GIOCondition cond, gpointer data) { int x; diff --git a/src/signal.c b/src/signal.c new file mode 100644 index 0000000..536f8b3 --- /dev/null +++ b/src/signal.c @@ -0,0 +1,166 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include +#include +#include + +#include + +#include +#include + +#include "pkgmgr-server.h" + +#define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER) + +static int __get_uid_list(uid_t target_uid, uid_t **uids) +{ + int n; + + if (target_uid != GLOBAL_USER) { + *uids = malloc(sizeof(uid_t)); + if (*uids == NULL) { + ERR("out of memory"); + return 0; + } + (*uids)[0] = target_uid; + n = 1; + } else { + n = sd_get_uids(uids); + if (n < 0) { + ERR("cannot get login user list"); + return 0; + } + } + + return n; +} + +static void __free_uid_list(uid_t *uids) +{ + free(uids); +} + +void __send_app_signal(uid_t uid, const char *req_id, + const char *pkgid, const char *appid, + const char *key, const char *val, int req_type) +{ + pkgmgr_installer *pi; + uid_t *uids = NULL; + int n; + int i; + + pi = pkgmgr_installer_new(); + if (!pi) { + DBG("Failure in creating the pkgmgr_installer object"); + return; + } + + if (pkgmgr_installer_set_uid(pi, uid)) + goto catch; + + switch (req_type) { + case PKGMGR_REQUEST_TYPE_ENABLE_GLOBAL_APP_FOR_UID: + case PKGMGR_REQUEST_TYPE_ENABLE_APP: + if (pkgmgr_installer_set_request_type(pi, + PKGMGR_REQ_ENABLE_APP)) + goto catch; + break; + case PKGMGR_REQUEST_TYPE_DISABLE_GLOBAL_APP_FOR_UID: + case PKGMGR_REQUEST_TYPE_DISABLE_APP: + if (pkgmgr_installer_set_request_type(pi, + PKGMGR_REQ_DISABLE_APP)) + goto catch; + break; + case PKGMGR_REQUEST_TYPE_ENABLE_APP_SPLASH_SCREEN: + if (pkgmgr_installer_set_request_type(pi, + PKGMGR_REQ_ENABLE_APP_SPLASH_SCREEN)) + goto catch; + break; + case PKGMGR_REQUEST_TYPE_DISABLE_APP_SPLASH_SCREEN: + if (pkgmgr_installer_set_request_type(pi, + PKGMGR_REQ_DISABLE_APP_SPLASH_SCREEN)) + goto catch; + break; + default: + DBG("Unsupported req_type[%d]", req_type); + goto catch; + } + + if (pkgmgr_installer_set_session_id(pi, req_id)) + goto catch; + pkgmgr_installer_send_app_signal(pi, "app", pkgid, appid, key, val); + n = __get_uid_list(uid, &uids); + for (i = 0; i < n; i++) + pkgmgr_installer_send_app_signal_for_uid(pi, uids[i], "app", + pkgid, appid, key, val); + +catch: + __free_uid_list(uids); + pkgmgr_installer_free(pi); + + return; +} + +void __send_fail_signal(backend_info *info) +{ + int req_type; + pkgmgr_installer *pi; + uid_t *uids = NULL; + int n; + int i; + + pi = pkgmgr_installer_new(); + if (!pi) { + ERR("Failure in creating the pkgmgr_installer object"); + return; + } + pkgmgr_installer_set_session_id(pi, info->req_id); + switch (info->req_type) { + case PKGMGR_REQUEST_TYPE_INSTALL: + case PKGMGR_REQUEST_TYPE_MOUNT_INSTALL: + case PKGMGR_REQUEST_TYPE_REINSTALL: + req_type = PKGMGR_REQ_INSTALL; + break; + case PKGMGR_REQUEST_TYPE_UNINSTALL: + req_type = PKGMGR_REQ_UNINSTALL; + break; + case PKGMGR_REQUEST_TYPE_MOVE: + req_type = PKGMGR_REQ_MOVE; + break; + case PKGMGR_REQUEST_TYPE_GETSIZE: + req_type = PKGMGR_REQ_GETSIZE; + break; + default: + req_type = PKGMGR_REQ_INVALID; + break; + } + pkgmgr_installer_set_request_type(pi, req_type); + pkgmgr_installer_send_signal(pi, info->pkgtype, info->pkgid, + "end", "fail"); + n = __get_uid_list(info->uid, &uids); + for (i = 0; i < n; i++) + pkgmgr_installer_send_signal_for_uid(pi, uids[i], + info->pkgtype, info->pkgid, "end", "fail"); + + __free_uid_list(uids); + pkgmgr_installer_free(pi); + return; +} + + -- 2.7.4 From 2bfbc09eb9a2e8a2162e91c2ae6fdc4cbce8d71c Mon Sep 17 00:00:00 2001 From: Sangyoon Jang Date: Tue, 13 Sep 2016 10:37:47 +0900 Subject: [PATCH 06/16] Get actucal pkgid first and then send signal For sending pkgid, appid pair correctly, get pkgid from appid first. Change-Id: I72f682b2e519ebd96d5d812d3fb05256a2eb0277 Signed-off-by: Sangyoon Jang --- src/pkgmgr-server.c | 47 ++++++++++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 17 deletions(-) diff --git a/src/pkgmgr-server.c b/src/pkgmgr-server.c index 061c2b8..505c874 100644 --- a/src/pkgmgr-server.c +++ b/src/pkgmgr-server.c @@ -923,19 +923,22 @@ static int __process_enable_app(pm_dbus_msg *item) int ret = -1; bool is_global = false; - __send_app_signal(item->uid, item->req_id, item->pkgid, item->pkgid, - PKGMGR_INSTALLER_START_KEY_STR, - PKGMGR_INSTALLER_APP_ENABLE_EVENT_STR, item->req_type); - /* get actual pkgid and replace it to appid which is currently stored at pkgid variable */ ret = __change_item_info(item, item->uid, &is_global); if (ret != PMINFO_R_OK || strlen(item->appid) == 0) { __send_app_signal(item->uid, item->req_id, item->pkgid, item->pkgid, + PKGMGR_INSTALLER_START_KEY_STR, + PKGMGR_INSTALLER_APP_ENABLE_EVENT_STR, item->req_type); + __send_app_signal(item->uid, item->req_id, item->pkgid, item->pkgid, PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_FAIL_EVENT_STR, item->req_type); return ret; } + __send_app_signal(item->uid, item->req_id, item->pkgid, item->appid, + PKGMGR_INSTALLER_START_KEY_STR, + PKGMGR_INSTALLER_APP_ENABLE_EVENT_STR, item->req_type); + ret = pkgmgr_parser_update_app_disable_info_in_usr_db(item->appid, item->uid, 0); if (ret != PMINFO_R_OK) __send_app_signal(item->uid, item->req_id, item->pkgid, item->appid, @@ -955,19 +958,22 @@ static int __process_disable_app(pm_dbus_msg *item) int ret = -1; bool is_global = false; - __send_app_signal(item->uid, item->req_id, item->pkgid, item->pkgid, - PKGMGR_INSTALLER_START_KEY_STR, - PKGMGR_INSTALLER_APP_DISABLE_EVENT_STR, item->req_type); - /* get actual pkgid and replace it to appid which is currently stored at pkgid variable */ ret = __change_item_info(item, item->uid, &is_global); if (ret != PMINFO_R_OK || strlen(item->appid) == 0) { __send_app_signal(item->uid, item->req_id, item->pkgid, item->pkgid, + PKGMGR_INSTALLER_START_KEY_STR, + PKGMGR_INSTALLER_APP_DISABLE_EVENT_STR, item->req_type); + __send_app_signal(item->uid, item->req_id, item->pkgid, item->pkgid, PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_FAIL_EVENT_STR, item->req_type); return ret; } + __send_app_signal(item->uid, item->req_id, item->pkgid, item->appid, + PKGMGR_INSTALLER_START_KEY_STR, + PKGMGR_INSTALLER_APP_DISABLE_EVENT_STR, item->req_type); + ret = __kill_app(item->appid, item->uid); if (ret != PMINFO_R_OK) { __send_app_signal(item->uid, item->req_id, item->pkgid, item->appid, @@ -993,19 +999,22 @@ static int __process_enable_global_app_for_uid(pm_dbus_msg *item) int ret = -1; bool is_global = true; - __send_app_signal(item->uid, item->req_id, item->pkgid, item->pkgid, - PKGMGR_INSTALLER_START_KEY_STR, - PKGMGR_INSTALLER_GLOBAL_APP_ENABLE_FOR_UID, item->req_type); - /* get actual pkgid and replace it to appid which is currently stored at pkgid variable */ ret = __change_item_info(item, item->uid, &is_global); if (ret != PMINFO_R_OK || strlen(item->appid) == 0) { __send_app_signal(item->uid, item->req_id, item->pkgid, item->pkgid, + PKGMGR_INSTALLER_START_KEY_STR, + PKGMGR_INSTALLER_GLOBAL_APP_ENABLE_FOR_UID, item->req_type); + __send_app_signal(item->uid, item->req_id, item->pkgid, item->pkgid, PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_FAIL_EVENT_STR, item->req_type); return ret; } + __send_app_signal(item->uid, item->req_id, item->pkgid, item->appid, + PKGMGR_INSTALLER_START_KEY_STR, + PKGMGR_INSTALLER_GLOBAL_APP_ENABLE_FOR_UID, item->req_type); + ret = pkgmgr_parser_update_global_app_disable_for_uid_info_in_db(item->appid, item->uid, 0); if (ret != PMINFO_R_OK) __send_app_signal(item->uid, item->req_id, item->pkgid, item->appid, @@ -1024,20 +1033,24 @@ static int __process_disable_global_app_for_uid(pm_dbus_msg *item) int ret = -1; bool is_global = true; - __send_app_signal(item->uid, item->req_id, - item->pkgid, item->pkgid, - PKGMGR_INSTALLER_START_KEY_STR, - PKGMGR_INSTALLER_GLOBAL_APP_DISABLE_FOR_UID, item->req_type); - /* get actual pkgid and replace it to appid which is currently stored at pkgid variable */ ret = __change_item_info(item, GLOBAL_USER, &is_global); if (ret != PMINFO_R_OK || strlen(item->appid) == 0) { + __send_app_signal(item->uid, item->req_id, + item->pkgid, item->pkgid, + PKGMGR_INSTALLER_START_KEY_STR, + PKGMGR_INSTALLER_GLOBAL_APP_DISABLE_FOR_UID, item->req_type); __send_app_signal(item->uid, item->req_id, item->pkgid, item->pkgid, PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_FAIL_EVENT_STR, item->req_type); return ret; } + __send_app_signal(item->uid, item->req_id, + item->pkgid, item->appid, + PKGMGR_INSTALLER_START_KEY_STR, + PKGMGR_INSTALLER_GLOBAL_APP_DISABLE_FOR_UID, item->req_type); + ret = __kill_app(item->appid, item->uid); ret = pkgmgr_parser_update_global_app_disable_for_uid_info_in_db(item->appid, item->uid, 1); -- 2.7.4 From 03519278ee430b3e6acca68b59717b29d4352e5c Mon Sep 17 00:00:00 2001 From: jongmyeongko Date: Tue, 27 Sep 2016 11:27:43 +0900 Subject: [PATCH 07/16] suppess build warning on the profile which doesn't support CSR feature. Change-Id: I2a22e1002e417abdb7b03c43e794e830b14bbbbf Signed-off-by: jongmyeongko --- src/pkgmgr-server.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/pkgmgr-server.c b/src/pkgmgr-server.c index 505c874..64b87bc 100644 --- a/src/pkgmgr-server.c +++ b/src/pkgmgr-server.c @@ -1486,7 +1486,9 @@ gboolean queue_job(void *data) break; } +#ifdef TIZEN_FEATURE_CSR end: +#endif ptr->pid = ret; free(item); -- 2.7.4 From 8f546e002cd0cebe75656c670c36760cec05aaa2 Mon Sep 17 00:00:00 2001 From: Junghyun Yeon Date: Tue, 27 Sep 2016 08:23:31 +0900 Subject: [PATCH 08/16] Set busy status flag on pkg enable/disable Change-Id: Ia27ff96bd2deec12162243a339d286fc9fa93335 Signed-off-by: Junghyun Yeon --- src/pkgmgr-server.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/pkgmgr-server.c b/src/pkgmgr-server.c index 64b87bc..6ef1661 100644 --- a/src/pkgmgr-server.c +++ b/src/pkgmgr-server.c @@ -1422,9 +1422,11 @@ gboolean queue_job(void *data) ret = __process_move(item); break; case PKGMGR_REQUEST_TYPE_ENABLE_PKG: + __set_backend_busy(x); ret = __process_enable_pkg(item); break; case PKGMGR_REQUEST_TYPE_DISABLE_PKG: + __set_backend_busy(x); ret = __process_disable_pkg(item); break; case PKGMGR_REQUEST_TYPE_ENABLE_APP: -- 2.7.4 From 6db02013234ecaa4e98423da805c96e6a86b8674 Mon Sep 17 00:00:00 2001 From: jongmyeongko Date: Mon, 10 Oct 2016 23:35:34 +0900 Subject: [PATCH 09/16] fix wrong behavior of pkg_getsize - set uid/gid for pkg_getsize Change-Id: I57c33ae74d33148350520776d34db24bcc5ba6c9 Signed-off-by: jongmyeongko --- src/pkgmgr-server.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/pkgmgr-server.c b/src/pkgmgr-server.c index 6ef1661..764894a 100644 --- a/src/pkgmgr-server.c +++ b/src/pkgmgr-server.c @@ -533,6 +533,18 @@ int set_environement(user_ctx *ctx) if (!ctx) return -1; + if (ctx->uid != APPFW_UID) { + if (setuid(ctx->uid)) { + ERR("setuid failed: %d", errno); + return -1; + } + + if (setgid(ctx->gid)) { + ERR("setgid failed: %d", errno); + return -1; + } + } + n = getgroups(0, NULL); if (n < 0) { ERR("Failed to get the number of supplementary group IDs"); -- 2.7.4 From 4257da53934d4d6e1f0780d81d5c0bb748698692 Mon Sep 17 00:00:00 2001 From: Sangyoon Jang Date: Wed, 12 Oct 2016 13:52:00 +0900 Subject: [PATCH 10/16] Kill app using aul api instead of proc filesystem Change-Id: Ic48077821e5c81b378510deba30ecf0741b5e310 Signed-off-by: Sangyoon Jang --- CMakeLists.txt | 2 +- packaging/pkgmgr-server.spec | 1 + src/pkgmgr-server.c | 152 +++++++++++++------------------------------ 3 files changed, 46 insertions(+), 109 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3abb01a..3c76497 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,7 +33,7 @@ SET(SRCS src/signal.c ) -SET(SERVER_CHECK_MODULES gio-2.0 dlog pkgmgr-parser pkgmgr-info libtzplatform-config drm-service-core-tizen libgum sqlite3 pkgmgr pkgmgr-installer libsystemd) +SET(SERVER_CHECK_MODULES gio-2.0 dlog pkgmgr-parser pkgmgr-info libtzplatform-config drm-service-core-tizen libgum sqlite3 pkgmgr pkgmgr-installer libsystemd aul) IF(TIZEN_FEATURE_CSR) SET(SERVER_CHECK_MODULES "${SERVER_CHECK_MODULES} csr") ENDIF(TIZEN_FEATURE_CSR) diff --git a/packaging/pkgmgr-server.spec b/packaging/pkgmgr-server.spec index dbb360f..ef78063 100644 --- a/packaging/pkgmgr-server.spec +++ b/packaging/pkgmgr-server.spec @@ -13,6 +13,7 @@ BuildRequires: pkgconfig(dbus-glib-1) BuildRequires: pkgconfig(glib-2.0) BuildRequires: pkgconfig(gio-2.0) BuildRequires: pkgconfig(dlog) +BuildRequires: pkgconfig(aul) BuildRequires: pkgconfig(bundle) BuildRequires: pkgconfig(pkgmgr-info) BuildRequires: pkgconfig(iniparser) diff --git a/src/pkgmgr-server.c b/src/pkgmgr-server.c index 764894a..2abd40f 100644 --- a/src/pkgmgr-server.c +++ b/src/pkgmgr-server.c @@ -29,7 +29,6 @@ #include #include #include -#include #include #include #include @@ -38,6 +37,7 @@ #include #include +#include #include #include #include @@ -291,44 +291,6 @@ gboolean exit_server(void *data) return TRUE; } -static int __pkgcmd_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 int __pkgcmd_find_pid_by_cmdline(const char *dname, - const char *cmdline, const char *apppath) -{ - int pid = 0; - int pgid = 0; - - if (strcmp(cmdline, apppath) == 0) { - pid = atoi(dname); - pgid = getpgid(pid); - if (pgid < 0) { - ERR("getpgid failed, errno(%d)", errno); - pid = 0; - } - if (pid != pgid) - pid = 0; - } - return pid; -} - #ifdef TIZEN_FEATURE_CSR static int __check_csr(backend_info *ptr) { @@ -357,55 +319,6 @@ static int __check_csr(backend_info *ptr) } #endif -static int __pkgcmd_proc_iter_kill_cmdline(const char *apppath, int option) -{ - DIR *dp; - struct dirent dentry, *result; - int pid; - int ret; - char buf[1024] = {'\0'}; - int pgid; - - dp = opendir("/proc"); - if (dp == NULL) - return -1; - - for (ret = readdir_r(dp, &dentry, &result); - ret == 0 && result != NULL; - ret = readdir_r(dp, &dentry, &result)) { - if (!isdigit(dentry.d_name[0])) - continue; - - snprintf(buf, sizeof(buf), "/proc/%s/cmdline", dentry.d_name); - ret = __pkgcmd_read_proc(buf, buf, sizeof(buf)); - if (ret <= 0) - continue; - - pid = __pkgcmd_find_pid_by_cmdline(dentry.d_name, buf, apppath); - if (pid > 0) { - if (option == 0) { - closedir(dp); - return pid; - } - pgid = getpgid(pid); - if (pgid <= 1) { - closedir(dp); - ERR("getpgid failed, errno(%d)", errno); - return -1; - } - if (killpg(pgid, SIGKILL) < 0) { - closedir(dp); - ERR("killpg failed, errno(%d)", errno); - return -1; - } - closedir(dp); - return pid; - } - } - closedir(dp); - return 0; -} - static void __make_pid_info_file(char *req_key, int pid, uid_t uid) { FILE* file; @@ -450,31 +363,46 @@ static void __make_pid_info_file(char *req_key, int pid, uid_t uid) static int __kill_app(char *appid, uid_t uid) { - pkgmgrinfo_appinfo_h appinfo; - int ret = PMINFO_R_ERROR; - char *exec = NULL; + int ret; + int pid; + int is_running; - ret = pkgmgrinfo_appinfo_get_usr_appinfo(appid, uid, &appinfo); - if (ret != PMINFO_R_OK) - return PMINFO_R_ERROR; + is_running = aul_app_is_running_for_uid(appid, uid); + /* app is not running */ + if (!is_running) + return 0; - ret = pkgmgrinfo_appinfo_get_exec(appinfo, &exec); - if (ret != PMINFO_R_OK) { - pkgmgrinfo_appinfo_destroy_appinfo(appinfo); - return PMINFO_R_ERROR; + pid = aul_app_get_pid_for_uid(appid, uid); + if (pid == -1) + return -1; + + ret = aul_terminate_pid_for_uid(pid, uid); + if (ret != AUL_R_OK) { + ERR("failed to terminate app(%d)", appid); + return -1; } - ret = __pkgcmd_proc_iter_kill_cmdline(exec, 1); - if (ret != PMINFO_R_OK) - DBG("failed to kill app[%s], exec[%s]", appid, exec); + return 0; +} - pkgmgrinfo_appinfo_destroy_appinfo(appinfo); - return ret; +static int __check_app(char *appid, uid_t uid) +{ + int pid; + int is_running; + + is_running = aul_app_is_running_for_uid(appid, uid); + if (!is_running) + return 0; + + pid = aul_app_get_pid_for_uid(appid, uid); + + return pid; } static int __pkgcmd_app_cb(const pkgmgrinfo_appinfo_h handle, void *user_data) { char *pkgid; + char *appid; char *exec; int ret; int pid = -1; @@ -489,16 +417,24 @@ static int __pkgcmd_app_cb(const pkgmgrinfo_appinfo_h handle, void *user_data) perror("Failed to get app exec path\n"); exit(1); } + ret = pkgmgrinfo_appinfo_get_appid(handle, &appid); + if (ret) { + perror("Failed to get appid\n"); + exit(1); + } ret = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgid); if (ret) { perror("Failed to get pkgid\n"); exit(1); } - if (strcmp(pdata->cmd, "kill") == 0) - pid = __pkgcmd_proc_iter_kill_cmdline(exec, 1); - else if (strcmp(pdata->cmd, "check") == 0) - pid = __pkgcmd_proc_iter_kill_cmdline(exec, 0); + if (strcmp(pdata->cmd, "kill") == 0) { + pid = __check_app(appid, pdata->uid); + if (pid > 0) + ret = __kill_app(appid, pdata->uid); + } else if (strcmp(pdata->cmd, "check") == 0) { + pid = __check_app(appid, pdata->uid); + } __make_pid_info_file(pkgid, pid, pdata->uid); @@ -987,7 +923,7 @@ static int __process_disable_app(pm_dbus_msg *item) PKGMGR_INSTALLER_APP_DISABLE_EVENT_STR, item->req_type); ret = __kill_app(item->appid, item->uid); - if (ret != PMINFO_R_OK) { + if (ret != 0) { __send_app_signal(item->uid, item->req_id, item->pkgid, item->appid, PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_FAIL_EVENT_STR, item->req_type); -- 2.7.4 From b3314aa160c433ec64c3f15dfb3b515f4f72e2d2 Mon Sep 17 00:00:00 2001 From: Sangyoon Jang Date: Wed, 12 Oct 2016 15:22:55 +0900 Subject: [PATCH 11/16] Fix returning error to client Return ENOMEM when memory allocation failed. Change-Id: I4b4c0b8777c9f8a18fc1c1955e923d7ee3f290c1 Signed-off-by: Sangyoon Jang --- src/request.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 48 insertions(+), 9 deletions(-) diff --git a/src/request.c b/src/request.c index 8f5e3f1..d4d049f 100644 --- a/src/request.c +++ b/src/request.c @@ -283,7 +283,9 @@ static int __handle_request_install(uid_t uid, args = (char *)calloc(len, sizeof(char)); if (args == NULL) { ERR("calloc failed"); - ret = -1; + g_dbus_method_invocation_return_value(invocation, + g_variant_new("(is)", PKGMGR_R_ENOMEM, "")); + ret = -1; goto catch; } @@ -309,6 +311,8 @@ static int __handle_request_install(uid_t uid, reqkey = __generate_reqkey(pkgpath); if (reqkey == NULL) { + g_dbus_method_invocation_return_value(invocation, + g_variant_new("(is)", PKGMGR_R_ENOMEM, "")); ret = -1; goto catch; } @@ -360,7 +364,9 @@ static int __handle_request_mount_install(uid_t uid, args = (char *)calloc(len, sizeof(char)); if (args == NULL) { ERR("calloc failed"); - ret = -1; + g_dbus_method_invocation_return_value(invocation, + g_variant_new("(is)", PKGMGR_R_ENOMEM, "")); + ret = -1; goto catch; } @@ -386,6 +392,8 @@ static int __handle_request_mount_install(uid_t uid, reqkey = __generate_reqkey(pkgpath); if (reqkey == NULL) { + g_dbus_method_invocation_return_value(invocation, + g_variant_new("(is)", PKGMGR_R_ENOMEM, "")); ret = -1; goto catch; } @@ -428,8 +436,11 @@ static int __handle_request_reinstall(uid_t uid, } reqkey = __generate_reqkey(pkgid); - if (reqkey == NULL) + if (reqkey == NULL) { + g_dbus_method_invocation_return_value(invocation, + g_variant_new("(is)", PKGMGR_R_ENOMEM, "")); return -1; + } if (_pm_queue_push(target_uid, reqkey, PKGMGR_REQUEST_TYPE_REINSTALL, pkgtype, pkgid, "")) { g_dbus_method_invocation_return_value(invocation, @@ -461,8 +472,11 @@ static int __handle_request_uninstall(uid_t uid, } reqkey = __generate_reqkey(pkgid); - if (reqkey == NULL) + if (reqkey == NULL) { + g_dbus_method_invocation_return_value(invocation, + g_variant_new("(is)", PKGMGR_R_ENOMEM, "")); return -1; + } if (_pm_queue_push(target_uid, reqkey, PKGMGR_REQUEST_TYPE_UNINSTALL, pkgtype, pkgid, "")) { g_dbus_method_invocation_return_value(invocation, @@ -496,8 +510,11 @@ static int __handle_request_move(uid_t uid, } reqkey = __generate_reqkey(pkgid); - if (reqkey == NULL) + if (reqkey == NULL) { + g_dbus_method_invocation_return_value(invocation, + g_variant_new("(is)", PKGMGR_R_ENOMEM, "")); return -1; + } snprintf(buf, sizeof(buf), "%d", move_type); if (_pm_queue_push(target_uid, reqkey, PKGMGR_REQUEST_TYPE_MOVE, pkgtype, @@ -531,8 +548,11 @@ static int __handle_request_enable_pkg(uid_t uid, } reqkey = __generate_reqkey(pkgid); - if (reqkey == NULL) + if (reqkey == NULL) { + g_dbus_method_invocation_return_value(invocation, + g_variant_new("(i)", PKGMGR_R_ENOMEM)); return -1; + } if (_pm_queue_push(target_uid, reqkey, PKGMGR_REQUEST_TYPE_ENABLE_PKG, pkgtype, pkgid, "")) { @@ -565,8 +585,11 @@ static int __handle_request_disable_pkg(uid_t uid, } reqkey = __generate_reqkey(pkgid); - if (reqkey == NULL) + if (reqkey == NULL) { + g_dbus_method_invocation_return_value(invocation, + g_variant_new("(i)", PKGMGR_R_ENOMEM)); return -1; + } if (_pm_queue_push(target_uid, reqkey, PKGMGR_REQUEST_TYPE_DISABLE_PKG, pkgtype, pkgid, "")) { @@ -600,6 +623,8 @@ static int __handle_request_enable_app(uid_t uid, reqkey = __generate_reqkey(appid); if (reqkey == NULL) { + g_dbus_method_invocation_return_value(invocation, + g_variant_new("(is)", PKGMGR_R_ENOMEM, "")); ret = -1; goto catch; } @@ -641,6 +666,8 @@ static int __handle_request_disable_app(uid_t uid, reqkey = __generate_reqkey(appid); if (reqkey == NULL) { + g_dbus_method_invocation_return_value(invocation, + g_variant_new("(is)", PKGMGR_R_ENOMEM, "")); ret = -1; goto catch; } @@ -682,6 +709,8 @@ static int __handle_request_enable_global_app_for_uid(uid_t uid, reqkey = __generate_reqkey(appid); if (reqkey == NULL) { + g_dbus_method_invocation_return_value(invocation, + g_variant_new("(is)", PKGMGR_R_ENOMEM, "")); ret = -1; goto catch; } @@ -723,6 +752,8 @@ static int __handle_request_disable_global_app_for_uid(uid_t uid, reqkey = __generate_reqkey(appid); if (reqkey == NULL) { + g_dbus_method_invocation_return_value(invocation, + g_variant_new("(is)", PKGMGR_R_ENOMEM, "")); ret = -1; goto catch; } @@ -764,8 +795,11 @@ static int __handle_request_getsize(uid_t uid, } reqkey = __generate_reqkey(pkgid); - if (reqkey == NULL) + if (reqkey == NULL) { + g_dbus_method_invocation_return_value(invocation, + g_variant_new("(is)", PKGMGR_R_ENOMEM, "")); return -1; + } snprintf(buf, sizeof(buf), "%d", get_type); if (_pm_queue_push(target_uid, reqkey, PKGMGR_REQUEST_TYPE_GETSIZE, "pkgtool", @@ -799,8 +833,11 @@ static int __handle_request_cleardata(uid_t uid, } reqkey = __generate_reqkey(pkgid); - if (reqkey == NULL) + if (reqkey == NULL) { + g_dbus_method_invocation_return_value(invocation, + g_variant_new("(i)", PKGMGR_R_ENOMEM)); return -1; + } if (_pm_queue_push(target_uid, reqkey, PKGMGR_REQUEST_TYPE_CLEARDATA, pkgtype, pkgid, "")) { @@ -1025,6 +1062,8 @@ static int __update_app_splash_screen(uid_t uid, reqkey = __generate_reqkey(appid); if (reqkey == NULL) { ERR("Failed to generate request key"); + g_dbus_method_invocation_return_value(invocation, + g_variant_new("(i)", PKGMGR_R_ENOMEM)); return -1; } -- 2.7.4 From 88951b80bdcf1bd17292dfc3e24851f0c7aeddfc Mon Sep 17 00:00:00 2001 From: Sangyoon Jang Date: Wed, 12 Oct 2016 15:25:08 +0900 Subject: [PATCH 12/16] Return kill/check result directly instead of writing on tmp file Submit together: - https://review.tizen.org/gerrit/91895 - https://review.tizen.org/gerrit/91896 Change-Id: I6d32d1f8fe93a8cbfb13429f34560024ac074549 Signed-off-by: Sangyoon Jang --- src/pkgmgr-server.c | 81 +++++++++++++++++------------------------------------ src/request.c | 44 +++++++++++++++++++++-------- 2 files changed, 58 insertions(+), 67 deletions(-) diff --git a/src/pkgmgr-server.c b/src/pkgmgr-server.c index 2abd40f..0986995 100644 --- a/src/pkgmgr-server.c +++ b/src/pkgmgr-server.c @@ -30,7 +30,6 @@ #include #include #include -#include #include #include @@ -73,6 +72,7 @@ typedef struct { typedef struct { uid_t uid; char *cmd; + int pid; } pkgcmd_data; /* @@ -319,48 +319,6 @@ static int __check_csr(backend_info *ptr) } #endif -static void __make_pid_info_file(char *req_key, int pid, uid_t uid) -{ - FILE* file; - int fd; - int ret; - char buf[MAX_PKG_TYPE_LEN] = {0}; - char info_file[PATH_MAX] = {'\0'}; - struct passwd pwd; - struct passwd *pwd_result; - - if (req_key == NULL) - return; - - ret = getpwuid_r(uid, &pwd, buf, sizeof(buf), &pwd_result); - if (ret != 0 || pwd_result == NULL) { - ERR("get uid failed(%d) for user(%d)", ret, uid); - return; - } - DBG("uid(%d), gid(%d)", uid, pwd.pw_gid); - - snprintf(info_file, PATH_MAX, "/tmp/pkgmgr/%s", req_key); - - DBG("info_path(%s)", info_file); - file = fopen(info_file, "w"); - if (file == NULL) { - ERR("Couldn't open the file(%s)", info_file); - return; - } - - snprintf(buf, MAX_PKG_TYPE_LEN, "%d\n", pid); - fwrite(buf, 1, strlen(buf), file); - - fflush(file); - fd = fileno(file); - if (fchmod(fd, 0777) < 0) - ERR("chmod failed, errno(%d)", errno); - if (fchown(fd, uid, pwd.pw_gid) < 0) - ERR("chown failed, errno(%d)", errno); - fsync(fd); - fclose(file); -} - static int __kill_app(char *appid, uid_t uid) { int ret; @@ -405,7 +363,6 @@ static int __pkgcmd_app_cb(const pkgmgrinfo_appinfo_h handle, void *user_data) char *appid; char *exec; int ret; - int pid = -1; pkgcmd_data *pdata = (pkgcmd_data *)user_data; if (handle == NULL) { @@ -429,15 +386,13 @@ static int __pkgcmd_app_cb(const pkgmgrinfo_appinfo_h handle, void *user_data) } if (strcmp(pdata->cmd, "kill") == 0) { - pid = __check_app(appid, pdata->uid); - if (pid > 0) + pdata->pid = __check_app(appid, pdata->uid); + if (pdata->pid > 0) ret = __kill_app(appid, pdata->uid); } else if (strcmp(pdata->cmd, "check") == 0) { - pid = __check_app(appid, pdata->uid); + pdata->pid = __check_app(appid, pdata->uid); } - __make_pid_info_file(pkgid, pid, pdata->uid); - return 0; } @@ -1076,33 +1031,41 @@ static int __process_kill(pm_dbus_msg *item) { int ret; pkgmgrinfo_pkginfo_h handle; - pkgcmd_data *pdata = NULL; + pkgcmd_data *pdata; ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(item->pkgid, item->uid, &handle); if (ret < 0) { ERR("Failed to get handle"); + __return_value_to_caller(item->req_id, + g_variant_new("(ii)", PKGMGR_R_ERROR, 0)); return -1; } pdata = calloc(1, sizeof(pkgcmd_data)); if (pdata == NULL) { ERR("memory alloc failed"); + __return_value_to_caller(item->req_id, + g_variant_new("(ii)", PKGMGR_R_ENOMEM, 0)); return -1; } pdata->cmd = strdup("kill"); if (pdata->cmd == NULL) { ERR("out of memory"); + __return_value_to_caller(item->req_id, + g_variant_new("(ii)", PKGMGR_R_ENOMEM, 0)); free(pdata); - pdata = NULL; return -1; } pdata->uid = item->uid; ret = pkgmgrinfo_appinfo_get_usr_list(handle, PMINFO_ALL_APP, __pkgcmd_app_cb, pdata, item->uid); + + __return_value_to_caller(item->req_id, + g_variant_new("(ii)", PKGMGR_R_OK, pdata->pid)); + free(pdata->cmd); free(pdata); - pdata = NULL; pkgmgrinfo_pkginfo_destroy_pkginfo(handle); if (ret < 0) { ERR("pkgmgrinfo_appinfo_get_list() failed"); @@ -1116,33 +1079,41 @@ static int __process_check(pm_dbus_msg *item) { int ret; pkgmgrinfo_pkginfo_h handle; - pkgcmd_data *pdata = NULL; + pkgcmd_data *pdata; ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(item->pkgid, item->uid, &handle); if (ret < 0) { ERR("Failed to get handle"); + __return_value_to_caller(item->req_id, + g_variant_new("(ii)", PKGMGR_R_ERROR, 0)); return -1; } pdata = calloc(1, sizeof(pkgcmd_data)); if (pdata == NULL) { ERR("memory alloc failed"); + __return_value_to_caller(item->req_id, + g_variant_new("(ii)", PKGMGR_R_ENOMEM, 0)); return -1; } pdata->cmd = strdup("check"); if (pdata->cmd == NULL) { ERR("out of memory"); + __return_value_to_caller(item->req_id, + g_variant_new("(ii)", PKGMGR_R_ENOMEM, 0)); free(pdata); - pdata = NULL; return -1; } pdata->uid = item->uid; ret = pkgmgrinfo_appinfo_get_usr_list(handle, PMINFO_ALL_APP, __pkgcmd_app_cb, pdata, item->uid); + + __return_value_to_caller(item->req_id, + g_variant_new("(ii)", PKGMGR_R_OK, pdata->pid)); + free(pdata->cmd); free(pdata); - pdata = NULL; pkgmgrinfo_pkginfo_destroy_pkginfo(handle); if (ret < 0) { ERR("pkgmgrinfo_appinfo_get_list() failed"); diff --git a/src/request.c b/src/request.c index d4d049f..e269030 100644 --- a/src/request.c +++ b/src/request.c @@ -113,11 +113,13 @@ static const char instropection_xml[] = " " " " " " + " " " " " " " " " " " " + " " " " " " " " @@ -886,23 +888,32 @@ static int __handle_request_kill(uid_t uid, { uid_t target_uid = (uid_t)-1; char *pkgid = NULL; + char *reqkey = NULL; g_variant_get(parameters, "(u&s)", &target_uid, &pkgid); if (target_uid == (uid_t)-1 || pkgid == NULL) { g_dbus_method_invocation_return_value(invocation, - g_variant_new("(i)", PKGMGR_R_ECOMM)); + g_variant_new("(ii)", PKGMGR_R_ECOMM, 0)); return -1; } - if (_pm_queue_push(target_uid, "", PKGMGR_REQUEST_TYPE_KILL, "default", - pkgid, "")) { + reqkey = __generate_reqkey(pkgid); + if (reqkey == NULL) { g_dbus_method_invocation_return_value(invocation, - g_variant_new("(i)", PKGMGR_R_ESYSTEM)); + g_variant_new("(ii)", PKGMGR_R_ENOMEM, 0)); return -1; } - g_dbus_method_invocation_return_value(invocation, - g_variant_new("(i)", PKGMGR_R_OK)); + if (_pm_queue_push(target_uid, reqkey, PKGMGR_REQUEST_TYPE_KILL, + "default", pkgid, "")) { + g_dbus_method_invocation_return_value(invocation, + g_variant_new("(ii)", PKGMGR_R_ESYSTEM, 0)); + return -1; + } + + if (!g_hash_table_insert(req_table, (gpointer)reqkey, + (gpointer)invocation)) + ERR("reqkey already exists"); return 0; } @@ -912,23 +923,32 @@ static int __handle_request_check(uid_t uid, { uid_t target_uid = (uid_t)-1; char *pkgid = NULL; + char *reqkey = NULL; g_variant_get(parameters, "(u&s)", &target_uid, &pkgid); if (target_uid == (uid_t)-1 || pkgid == NULL) { g_dbus_method_invocation_return_value(invocation, - g_variant_new("(i)", PKGMGR_R_ECOMM)); + g_variant_new("(ii)", PKGMGR_R_ECOMM, 0)); return -1; } - if (_pm_queue_push(target_uid, "", PKGMGR_REQUEST_TYPE_CHECK, "default", - pkgid, "")) { + reqkey = __generate_reqkey(pkgid); + if (reqkey == NULL) { g_dbus_method_invocation_return_value(invocation, - g_variant_new("(i)", PKGMGR_R_ESYSTEM)); + g_variant_new("(ii)", PKGMGR_R_ENOMEM, 0)); return -1; } - g_dbus_method_invocation_return_value(invocation, - g_variant_new("(i)", PKGMGR_R_OK)); + if (_pm_queue_push(target_uid, reqkey, PKGMGR_REQUEST_TYPE_CHECK, + "default", pkgid, "")) { + g_dbus_method_invocation_return_value(invocation, + g_variant_new("(ii)", PKGMGR_R_ESYSTEM, 0)); + return -1; + } + + if (!g_hash_table_insert(req_table, (gpointer)reqkey, + (gpointer)invocation)) + ERR("reqkey already exists"); return 0; } -- 2.7.4 From 533abaa1b525f2b30abda5d4927e0a9bfaf85465 Mon Sep 17 00:00:00 2001 From: Junghyun Yeon Date: Mon, 17 Oct 2016 11:35:23 +0900 Subject: [PATCH 13/16] Fix possible memory leak Change-Id: I1acc9ca9657532ec56a99f5bf63da642aff14562 Signed-off-by: Junghyun Yeon --- src/request.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/request.c b/src/request.c index e269030..a9385b8 100644 --- a/src/request.c +++ b/src/request.c @@ -908,6 +908,7 @@ static int __handle_request_kill(uid_t uid, "default", pkgid, "")) { g_dbus_method_invocation_return_value(invocation, g_variant_new("(ii)", PKGMGR_R_ESYSTEM, 0)); + free(reqkey); return -1; } @@ -943,6 +944,7 @@ static int __handle_request_check(uid_t uid, "default", pkgid, "")) { g_dbus_method_invocation_return_value(invocation, g_variant_new("(ii)", PKGMGR_R_ESYSTEM, 0)); + free(reqkey); return -1; } -- 2.7.4 From f717771528695cea50e1e591d267750e01ddf1d7 Mon Sep 17 00:00:00 2001 From: Junghyun Yeon Date: Wed, 19 Oct 2016 20:42:00 +0900 Subject: [PATCH 14/16] Fix CMakeLists for compatibility - Fix CMakeLists to include additional source files automatically Change-Id: I6990759ae72674e26dea5d3627d28d62740baca8 Signed-off-by: Junghyun Yeon --- CMakeLists.txt | 14 +++++--------- org.tizen.pkgmgr.conf.in => org.tizen.pkgmgr.conf | 0 packaging/pkgmgr-server.spec | 2 +- 3 files changed, 6 insertions(+), 10 deletions(-) rename org.tizen.pkgmgr.conf.in => org.tizen.pkgmgr.conf (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3c76497..fe7ecc3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,13 +25,7 @@ INCLUDE_DIRECTORIES(include) INCLUDE(FindPkgConfig) SET(PKGMGR_SERVER "pkgmgr-server") -SET(SRCS - src/pkgmgr-server.c - src/request.c - src/pm-queue.c - src/restriction_mode.c - src/signal.c - ) +AUX_SOURCE_DIRECTORY(src SRCS) SET(SERVER_CHECK_MODULES gio-2.0 dlog pkgmgr-parser pkgmgr-info libtzplatform-config drm-service-core-tizen libgum sqlite3 pkgmgr pkgmgr-installer libsystemd aul) IF(TIZEN_FEATURE_CSR) @@ -53,10 +47,12 @@ TARGET_LINK_LIBRARIES(${PKGMGR_SERVER} pkgmgr_installer) TARGET_LINK_LIBRARIES(${PKGMGR_SERVER} ${SERVER_DEPS_LDFLAGS}) CONFIGURE_FILE(org.tizen.pkgmgr.service.in org.tizen.pkgmgr.service @ONLY) -CONFIGURE_FILE(org.tizen.pkgmgr.conf.in org.tizen.pkgmgr.conf @ONLY) CONFIGURE_FILE(package-manager.service.in package-manager.service @ONLY) INSTALL(TARGETS ${PKGMGR_SERVER} DESTINATION bin) INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/org.tizen.pkgmgr.service DESTINATION ${PREFIX}/share/dbus-1/system-services/) -INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/org.tizen.pkgmgr.conf DESTINATION ${SYSCONF_INSTALL_DIR}/dbus-1/system.d/) +INSTALL(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/ DESTINATION ${SYSCONF_INSTALL_DIR}/dbus-1/system.d + FILES_MATCHING + PATTERN "*.conf") + INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/package-manager.service DESTINATION ${UNITDIR}) diff --git a/org.tizen.pkgmgr.conf.in b/org.tizen.pkgmgr.conf similarity index 100% rename from org.tizen.pkgmgr.conf.in rename to org.tizen.pkgmgr.conf diff --git a/packaging/pkgmgr-server.spec b/packaging/pkgmgr-server.spec index ef78063..1fcf88e 100644 --- a/packaging/pkgmgr-server.spec +++ b/packaging/pkgmgr-server.spec @@ -82,7 +82,7 @@ install -m 0600 restriction.db %{buildroot}%{db_dir} %defattr(-,root,root,-) %{_unitdir}/package-manager.service %{_datadir}/dbus-1/system-services/org.tizen.pkgmgr.service -%config %{_sysconfdir}/dbus-1/system.d/org.tizen.pkgmgr.conf +%config %{_sysconfdir}/dbus-1/system.d/*pkgmgr*.conf %config(noreplace) %{db_dir} %config(noreplace) %{db_dir}/restriction.db %{_bindir}/pkgmgr-server -- 2.7.4 From b0093e5209ab3d4010cd3f4a6ec8c1465c83a0e2 Mon Sep 17 00:00:00 2001 From: Sangyoon Jang Date: Thu, 27 Oct 2016 15:30:10 +0900 Subject: [PATCH 15/16] Fix queue msg args buffer size issue Alloc memory for args dynamically. Change-Id: I7ed8d06477836287a1d994088959c43324c13d80 Signed-off-by: Sangyoon Jang --- include/pkgmgr-server.h | 4 ++-- src/pkgmgr-server.c | 4 +++- src/pm-queue.c | 7 +++++-- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/include/pkgmgr-server.h b/include/pkgmgr-server.h index 13efc58..61b5696 100644 --- a/include/pkgmgr-server.h +++ b/include/pkgmgr-server.h @@ -90,7 +90,7 @@ typedef struct { char pkg_type[MAX_PKG_TYPE_LEN]; char pkgid[MAX_PKG_NAME_LEN]; char appid[MAX_PKG_NAME_LEN]; - char args[MAX_PKG_ARGS_LEN]; + char *args; } pm_dbus_msg; typedef struct backend_info_t { @@ -100,7 +100,7 @@ typedef struct backend_info_t { char req_id[MAX_REQ_ID_LEN]; char pkgtype[MAX_PKG_TYPE_LEN]; char pkgid[MAX_PKG_NAME_LEN]; - char args[MAX_PKG_ARGS_LEN]; + char *args; } backend_info; char *_get_backend_cmd(char *type); diff --git a/src/pkgmgr-server.c b/src/pkgmgr-server.c index 0986995..72d6cd3 100644 --- a/src/pkgmgr-server.c +++ b/src/pkgmgr-server.c @@ -1300,7 +1300,9 @@ gboolean queue_job(void *data) strncpy(ptr->req_id, item->req_id, MAX_REQ_ID_LEN - 1); strncpy(ptr->pkgtype, item->pkg_type, MAX_PKG_TYPE_LEN - 1); strncpy(ptr->pkgid, item->pkgid, MAX_PKG_NAME_LEN - 1); - strncpy(ptr->args, item->args, MAX_PKG_ARGS_LEN - 1); + free(ptr->args); + if (item->args) + ptr->args = strdup(item->args); memset((item->appid), 0, MAX_PKG_NAME_LEN); ptr->uid = item->uid; ptr->req_type = item->req_type; diff --git a/src/pm-queue.c b/src/pm-queue.c index 9ba8be9..7085367 100644 --- a/src/pm-queue.c +++ b/src/pm-queue.c @@ -279,7 +279,8 @@ int _pm_queue_push(uid_t uid, const char *req_id, int req_type, data->msg->uid = uid; snprintf(data->msg->pkg_type, sizeof(data->msg->pkg_type), "%s", type); snprintf(data->msg->pkgid, sizeof(data->msg->pkgid), "%s", pkgid); - snprintf(data->msg->args, sizeof(data->msg->args), "%s", args); + if (args) + data->msg->args = strdup(args); data->next = NULL; @@ -330,7 +331,8 @@ pm_dbus_msg *_pm_queue_pop(int position) ret->uid = cur->msg->uid; snprintf(ret->pkg_type, sizeof(ret->pkg_type), "%s", cur->msg->pkg_type); snprintf(ret->pkgid, sizeof(ret->pkgid), "%s", cur->msg->pkgid); - snprintf(ret->args, sizeof(ret->args), "%s", cur->msg->args); + if (cur->msg->args) + ret->args = strdup(cur->msg->args); ptr->head = cur->next; saveptr = ptr->head; @@ -397,6 +399,7 @@ void _pm_queue_final() prev->next = NULL; } + free(head[c]->msg->args); free(head[c]->msg); free(head[c]); -- 2.7.4 From 9978b7522e23a43ecf7b0021df62a65683fa99c1 Mon Sep 17 00:00:00 2001 From: Sangyoon Jang Date: Fri, 4 Nov 2016 15:00:44 +0900 Subject: [PATCH 16/16] Fix to disable/enable multiple packages Submit together: - https://review.tizen.org/gerrit/95565 Change-Id: Ib44668d5025b74414aa58ec9a9650a43540c03a2 Signed-off-by: Sangyoon Jang --- org.tizen.pkgmgr.conf | 4 +-- src/request.c | 86 ++++++++++++++++++++++++++++----------------------- 2 files changed, 50 insertions(+), 40 deletions(-) diff --git a/org.tizen.pkgmgr.conf b/org.tizen.pkgmgr.conf index 9d799ca..e94bf6c 100644 --- a/org.tizen.pkgmgr.conf +++ b/org.tizen.pkgmgr.conf @@ -36,8 +36,8 @@ - - + + diff --git a/src/request.c b/src/request.c index a9385b8..3ae16c7 100644 --- a/src/request.c +++ b/src/request.c @@ -55,16 +55,16 @@ static const char instropection_xml[] = " " " " " " - " " + " " " " " " - " " + " " " " " " - " " + " " " " " " - " " + " " " " " " " " @@ -534,76 +534,86 @@ static int __handle_request_move(uid_t uid, return 0; } -static int __handle_request_enable_pkg(uid_t uid, +static int __handle_request_enable_pkgs(uid_t uid, GDBusMethodInvocation *invocation, GVariant *parameters) { uid_t target_uid = (uid_t)-1; char *pkgtype = NULL; char *pkgid = NULL; char *reqkey = NULL; + GVariantIter *iter; - g_variant_get(parameters, "(u&s&s)", &target_uid, &pkgtype, &pkgid); - if (target_uid == (uid_t)-1 || pkgid == NULL) { + g_variant_get(parameters, "(u&sas)", &target_uid, &pkgtype, &iter); + if (target_uid == (uid_t)-1 || pkgtype == NULL || iter == NULL) { g_dbus_method_invocation_return_value(invocation, g_variant_new("(i)", PKGMGR_R_ECOMM)); return -1; } - reqkey = __generate_reqkey(pkgid); - if (reqkey == NULL) { - g_dbus_method_invocation_return_value(invocation, - g_variant_new("(i)", PKGMGR_R_ENOMEM)); - return -1; - } + while (g_variant_iter_loop(iter, "&s", &pkgid)) { + reqkey = __generate_reqkey(pkgid); + if (reqkey == NULL) { + g_dbus_method_invocation_return_value(invocation, + g_variant_new("(i)", PKGMGR_R_ENOMEM)); + return -1; + } + + if (_pm_queue_push(target_uid, reqkey, + PKGMGR_REQUEST_TYPE_ENABLE_PKG, + pkgtype, pkgid, "")) { + g_dbus_method_invocation_return_value(invocation, + g_variant_new("(i)", PKGMGR_R_ESYSTEM)); + free(reqkey); + return -1; + } - if (_pm_queue_push(target_uid, reqkey, PKGMGR_REQUEST_TYPE_ENABLE_PKG, pkgtype, - pkgid, "")) { - g_dbus_method_invocation_return_value(invocation, - g_variant_new("(i)", PKGMGR_R_ESYSTEM)); free(reqkey); - return -1; } g_dbus_method_invocation_return_value(invocation, g_variant_new("(i)", PKGMGR_R_OK)); - free(reqkey); return 0; } -static int __handle_request_disable_pkg(uid_t uid, +static int __handle_request_disable_pkgs(uid_t uid, GDBusMethodInvocation *invocation, GVariant *parameters) { uid_t target_uid = (uid_t)-1; char *pkgtype = NULL; char *pkgid = NULL; char *reqkey = NULL; + GVariantIter *iter; - g_variant_get(parameters, "(u&s&s)", &target_uid, &pkgtype, &pkgid); - if (target_uid == (uid_t)-1 || pkgid == NULL) { + g_variant_get(parameters, "(u&sas)", &target_uid, &pkgtype, &iter); + if (target_uid == (uid_t)-1 || pkgtype == NULL || iter == NULL) { g_dbus_method_invocation_return_value(invocation, g_variant_new("(i)", PKGMGR_R_ECOMM)); return -1; } - reqkey = __generate_reqkey(pkgid); - if (reqkey == NULL) { - g_dbus_method_invocation_return_value(invocation, - g_variant_new("(i)", PKGMGR_R_ENOMEM)); - return -1; - } + while (g_variant_iter_loop(iter, "&s", &pkgid)) { + reqkey = __generate_reqkey(pkgid); + if (reqkey == NULL) { + g_dbus_method_invocation_return_value(invocation, + g_variant_new("(i)", PKGMGR_R_ENOMEM)); + return -1; + } + + if (_pm_queue_push(target_uid, reqkey, + PKGMGR_REQUEST_TYPE_DISABLE_PKG, + pkgtype, pkgid, "")) { + g_dbus_method_invocation_return_value(invocation, + g_variant_new("(i)", PKGMGR_R_ESYSTEM)); + free(reqkey); + return -1; + } - if (_pm_queue_push(target_uid, reqkey, PKGMGR_REQUEST_TYPE_DISABLE_PKG, pkgtype, - pkgid, "")) { - g_dbus_method_invocation_return_value(invocation, - g_variant_new("(i)", PKGMGR_R_ESYSTEM)); free(reqkey); - return -1; } g_dbus_method_invocation_return_value(invocation, g_variant_new("(i)", PKGMGR_R_OK)); - free(reqkey); return 0; } @@ -1289,10 +1299,10 @@ static void __handle_method_call(GDBusConnection *connection, ret = __handle_request_cleardata(uid, invocation, parameters); else if (g_strcmp0(method_name, "move") == 0) ret = __handle_request_move(uid, invocation, parameters); - else if (g_strcmp0(method_name, "enable_pkg") == 0) - ret = __handle_request_enable_pkg(uid, invocation, parameters); - else if (g_strcmp0(method_name, "disable_pkg") == 0) - ret = __handle_request_disable_pkg(uid, invocation, parameters); + else if (g_strcmp0(method_name, "enable_pkgs") == 0) + ret = __handle_request_enable_pkgs(uid, invocation, parameters); + else if (g_strcmp0(method_name, "disable_pkgs") == 0) + ret = __handle_request_disable_pkgs(uid, invocation, parameters); else if (g_strcmp0(method_name, "getsize") == 0) ret = __handle_request_getsize(uid, invocation, parameters); else if (g_strcmp0(method_name, "clearcache") == 0) -- 2.7.4