From 7d6c99b8ffb4fe7666d5f083b321b0f6b585dbc3 Mon Sep 17 00:00:00 2001 From: jongmyeongko Date: Tue, 10 Nov 2015 17:58:28 +0900 Subject: [PATCH 01/16] merge tizen 2.4 Change-Id: I6808f3fe20e489ffb848a2feedba4803394857a1 Signed-off-by: jongmyeongko --- CMakeLists.txt | 5 +- include/eventsystem_daemon.h | 46 ++ packaging/esd.spec | 2 +- src/esd_main.c | 977 +++++++++++++++++++++++++++++-------------- src/esd_system_event.c | 603 ++++++++++++++++++++++++++ 5 files changed, 1309 insertions(+), 324 deletions(-) mode change 100755 => 100644 CMakeLists.txt create mode 100644 include/eventsystem_daemon.h mode change 100755 => 100644 packaging/esd.spec mode change 100755 => 100644 src/esd_main.c create mode 100644 src/esd_system_event.c diff --git a/CMakeLists.txt b/CMakeLists.txt old mode 100755 new mode 100644 index 7d16abc..06a859c --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -35,7 +35,10 @@ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}") SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed") ##build eventsystem daemon -add_executable(esd src/esd_main.c) +add_executable(esd + src/esd_main.c + src/esd_system_event.c +) TARGET_LINK_LIBRARIES(esd eventsystem pkgmgr-client ${pkgs_LDFLAGS}) SET_TARGET_PROPERTIES(esd PROPERTIES COMPILE_FLAGS ${CFLAGS} "-fPIE") SET_TARGET_PROPERTIES(esd PROPERTIES LINK_FLAGS "-pie") diff --git a/include/eventsystem_daemon.h b/include/eventsystem_daemon.h new file mode 100644 index 0000000..a06821d --- /dev/null +++ b/include/eventsystem_daemon.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2015 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. + */ + +#ifndef __EVENTSYSTEM_DAEMON_H__ +#define __EVENTSYSTEM_DAEMON_H__ + +/** + * header file for eventsystem_daemon + */ + +#ifdef __cplusplus +extern "C" { +#endif + + +#ifdef __cplusplus +} +#endif + +#undef LOG_TAG +#define LOG_TAG "ESD" + +#define _E(fmt, arg...) LOGE(fmt, ##arg) +#define _D(fmt, arg...) LOGD(fmt, ##arg) +#define _W(fmt, arg...) LOGW(fmt, ##arg) +#define _I(fmt, arg...) LOGI(fmt, ##arg) + +#define ESD_BOOT_COMPLETED "/tmp/esd_ready" + +int __esd_register_vconf_callbacks(void); + +#endif /* __EVENTSYSTEM_DAEMONE_H__ */ + diff --git a/packaging/esd.spec b/packaging/esd.spec old mode 100755 new mode 100644 index 6965731..b942935 --- a/packaging/esd.spec +++ b/packaging/esd.spec @@ -2,7 +2,7 @@ Name: esd Summary: Event system daemon Version: 0.0.1 Release: 1 -Group: Application Framework/Daemons +Group: Application Framework/Service License: Apache-2.0 Source0: %{name}-%{version}.tar.gz Source1: esd.service diff --git a/src/esd_main.c b/src/esd_main.c old mode 100755 new mode 100644 index bbb66ca..5486111 --- a/src/esd_main.c +++ b/src/esd_main.c @@ -14,33 +14,18 @@ #include #include #include +#include "eventsystem_daemon.h" -#undef LOG_TAG -#define LOG_TAG "ESD" - -#define _E(fmt, arg...) LOGE(fmt, ##arg) -#define _D(fmt, arg...) LOGD(fmt, ##arg) -#define _W(fmt, arg...) LOGW(fmt, ##arg) -#define _I(fmt, arg...) LOGI(fmt, ##arg) - -#define retvm_if(expr, val, fmt, arg...) do { \ - if (expr) { \ - _E(fmt, ##arg); \ - _E("(%s) -> %s() return", #expr, __func__); \ - return val; \ - } \ -} while (0) - -#define retv_if(expr, val) do { \ - if (expr) { \ - _E("(%s) -> %s() return", #expr, __func__); \ - return val; \ - } \ -} while (0) +static GHashTable *event_launch_table; /* table of events for launch_on_event*/ -#define ESD_BOOT_COMPLETED "/tmp/esd_ready" +static const char *allowed_event_list[] = { }; -static GHashTable *event_launch_table; /* table of events for launch_on_event*/ +static const char *event_launch_support_list[] = { + SYS_EVENT_BATTERY_CHARGER_STATUS, + SYS_EVENT_USB_STATUS, + SYS_EVENT_EARJACK_STATUS, + SYS_EVENT_INCOMMING_MSG +}; struct privilege_info { const char *event_name; @@ -60,7 +45,8 @@ static const char *earlier_event_list[] = { SYS_EVENT_ESD_STATUS, SYS_EVENT_LOW_MEMORY, SYS_EVENT_BOOT_COMPLETED, - SYS_EVENT_SYSTEM_SHUTDOWN + SYS_EVENT_SYSTEM_SHUTDOWN, + SYS_EVENT_BATTERY_CHARGER_STATUS }; static GHashTable *earlier_event_table; /* table of events for earlier_data */ @@ -125,18 +111,107 @@ static esd_info_s s_info; static void __esd_event_handler(char *event_name, bundle *data, void *user_data); static int __esd_add_appinfo_handler(const pkgmgrinfo_appinfo_h handle, void *data); -static int __get_sender_pid(GDBusConnection *conn, const char *sender_name) +/* TODO(jongmyeong.ko) */ +/* +static int __esd_get_visibility_from_cert_svc(const char *pkgid, int *visibility) +{ + int ret = ES_R_OK; + const char *cert_value = NULL; + pkgmgrinfo_certinfo_h certinfo = NULL; + + ret = pkgmgrinfo_pkginfo_create_certinfo(&certinfo); + if (ret != PMINFO_R_OK) { + _E("pkgmgrinfo_pkginfo_create_certinfo() failed."); + return ES_R_ERROR; + } + + ret = pkgmgrinfo_pkginfo_load_certinfo(pkgid, certinfo); + if (ret != PMINFO_R_OK) { + _E("pkgmgrinfo_pkginfo_load_certinfo() failed."); + ret = ES_R_ERROR; + goto end; + } + + ret = pkgmgrinfo_pkginfo_get_cert_value(certinfo, PMINFO_DISTRIBUTOR_ROOT_CERT, + &cert_value); + if (ret != PMINFO_R_OK) { + _E("pkgmgrinfo_pkginfo_get_cert_value() failed."); + ret = ES_R_ERROR; + goto end; + } + + ret = cert_svc_get_visibility_by_root_certificate(cert_value, + strlen(cert_value), visibility); + if (ret != CERT_SVC_ERR_NO_ERROR) { + _E("cert_svc_get_visibility_by_root_cert() failed. err = [%d]", ret); + ret = ES_R_ERROR; + goto end; + } + _D("visibility = [%d]", *visibility); + +end: + pkgmgrinfo_pkginfo_destroy_certinfo(certinfo); + + return ret; +} +*/ + +static int __esd_is_sending_allowed_event(const char *event_name) +{ + int i = 0; + int size = sizeof(allowed_event_list)/sizeof(*allowed_event_list); + + for (i = 0; i < size; i++) { + if (strcmp(allowed_event_list[i], event_name) == 0) { + return true; + } + } + + return false; +} + +#ifdef APPFW_EVENT_SYSTEM_EARLIER_FEATURE +static int __esd_check_earlier_support(const char *event_name) +{ + int i = 0; + int size = sizeof(earlier_event_list)/sizeof(*earlier_event_list); + + for (i = 0; i < size; i++) { + if (strcmp(earlier_event_list[i], event_name) == 0) { + return true; + } + } + + return false; +} +#endif + +static int __esd_check_event_launch_support(const char *event_name) +{ + int i = 0; + int size = sizeof(event_launch_support_list)/sizeof(*event_launch_support_list); + + for (i = 0; i < size; i++) { + if (strcmp(event_launch_support_list[i], event_name) == 0) { + return true; + } + } + + return false; +} + +static int __get_sender_unixinfo(GDBusConnection *conn, const char *sender_name, const char *type) { GDBusMessage *msg = NULL; GDBusMessage *reply = NULL; GError *err = NULL; GVariant *body; - int pid = 0; + int value = -1; msg = g_dbus_message_new_method_call("org.freedesktop.DBus", "/org/freedesktop/DBus", - "org.freedesktop.DBus", "GetConnectionUnixProcessID"); + "org.freedesktop.DBus", type); if (!msg) { - _D("Can't allocate new method call"); + _E("Can't allocate new method call"); goto out; } @@ -146,14 +221,14 @@ static int __get_sender_pid(GDBusConnection *conn, const char *sender_name) if (!reply) { if (err != NULL) { - _E("Failed to get pid [%s]", err->message); + _E("Failed to get info [%s]", err->message); g_error_free(err); } goto out; } body = g_dbus_message_get_body(reply); - g_variant_get(body, "(u)", &pid); + g_variant_get(body, "(u)", &value); out: if (msg) @@ -161,11 +236,38 @@ out: if (reply) g_object_unref(reply); + return value; +} + +static int __get_sender_pid(GDBusConnection *conn, const char *sender_name) +{ + int pid = 0; + + pid = __get_sender_unixinfo(conn, sender_name, "GetConnectionUnixProcessID"); + if (pid < 0) { + _E("failed to get pid"); + pid = 0; + } + _D("sender_name(%s), pid(%d)", sender_name, pid); return pid; } +static int __get_sender_uid(GDBusConnection *conn, const char *sender_name) +{ + int uid = -1; + + uid = __get_sender_unixinfo(conn, sender_name, "GetConnectionUnixUser"); + if (uid < 0) { + _E("failed to get uid"); + } + + _D("sender_name(%s), uid(%d)", sender_name, uid); + + return uid; +} + static int __esd_check_certificate_match(const char *app_id, const char *from_appid) { pkgmgrinfo_cert_compare_result_type_e res; @@ -204,7 +306,7 @@ static bool __esd_check_application_validation(const char *appid) return true; } -static void esd_trusted_busname_print_items(void) +static void __esd_trusted_busname_print_items(void) { GHashTableIter iter; gpointer key, value; @@ -219,7 +321,7 @@ static void esd_trusted_busname_print_items(void) } } -static int esd_trusted_busname_add_item(const char *appid, const char *busname, int pid) +static int __esd_trusted_busname_add_item(const char *appid, const char *busname, int pid) { char *app_id = NULL; char *bus_name = NULL; @@ -269,7 +371,7 @@ static int __esd_check_trusted_events(GDBusConnection *conn, const char *list_na GVariantIter *iter; gchar *str; char *ptr; - char tmp_appid[256] = {0, }; + char tmp_appid[128] = {0, }; int pid = 0; int ret = 0; @@ -296,7 +398,6 @@ static int __esd_check_trusted_events(GDBusConnection *conn, const char *list_na continue; } - _D("pid(%d)", pid); memset(tmp_appid, 0, sizeof(tmp_appid)); ret = aul_app_get_appid_bypid(pid, tmp_appid, sizeof(tmp_appid)); if (ret != AUL_R_OK) { @@ -307,7 +408,7 @@ static int __esd_check_trusted_events(GDBusConnection *conn, const char *list_na _D("appid(%s)", tmp_appid); if (__esd_check_application_validation(tmp_appid)) { _D("add to table"); - ret = esd_trusted_busname_add_item(tmp_appid, (const char *)str, pid); + ret = __esd_trusted_busname_add_item(tmp_appid, (const char *)str, pid); if (ret < 0) { _E("failed to add item"); } @@ -359,7 +460,7 @@ static bool __esd_check_valid_privilege(const char *appid, const char *privilege /* * ret = security_server_app_has_privilege(pkg_id, APP_TYPE_EFL, * privilege_name, &result); - * TODO : replace security_server api to cynara api. + * TODO(jongmyeong.ko) : replace security_server api to cynara api. */ result = 1; @@ -382,7 +483,7 @@ static bool __esd_check_valid_privilege(const char *appid, const char *privilege static int __esd_check_app_privileged_event(const char *appid, const char *event_name) { char *privilege_name = NULL; - int ret = 0; + int retval = 0; _D("appid(%s), event_name(%s)", appid, event_name); @@ -390,22 +491,15 @@ static int __esd_check_app_privileged_event(const char *appid, const char *event if (privilege_name && !__esd_check_valid_privilege(appid, privilege_name)) { _E("app(%s) has NOT privilege(%s)", appid, privilege_name); - ret = 0; + retval = 0; } else { - ret = 1; + retval = 1; } - return ret; -} - -void __esd_free_app_list(gpointer data) -{ - char *n = (char *)data; - - FREE_AND_NULL(n); + return retval; } -static void esd_print_appid_with_eventid(gpointer data, gpointer user_data) +static void __esd_print_appid_with_eventid(gpointer data, gpointer user_data) { esd_list_item_s *item = (esd_list_item_s *)data; char *event_name = (char *)user_data; @@ -413,15 +507,15 @@ static void esd_print_appid_with_eventid(gpointer data, gpointer user_data) _D("event_name(%s)-app_id(%s)-pkg_id(%s)", event_name, item->app_id, item->pkg_id); } -static void esd_print_interested_event(gpointer data, gpointer user_data) +static void __esd_print_interested_event(gpointer data, gpointer user_data) { event_launch_item *el_item = (event_launch_item *)data; char *event_name = (char *)el_item->event_name; _D("event_name = (%s)", event_name); - g_list_foreach(el_item->app_list_evtlaunch, esd_print_appid_with_eventid, event_name); + g_list_foreach(el_item->app_list_evtlaunch, __esd_print_appid_with_eventid, event_name); } -static void esd_launch_table_print_items(void) +static void __esd_launch_table_print_items(void) { GHashTableIter iter; gpointer key, value; @@ -429,11 +523,11 @@ static void esd_launch_table_print_items(void) g_hash_table_iter_init(&iter, event_launch_table); while (g_hash_table_iter_next(&iter, &key, &value)) { - esd_print_interested_event(value, NULL); + __esd_print_interested_event(value, NULL); } } -static int esd_find_compare_by_list_item(gconstpointer data, gconstpointer user_data) +static int __esd_find_compare_by_list_item(gconstpointer data, gconstpointer user_data) { esd_list_item_s *item_1 = (esd_list_item_s *)user_data; esd_list_item_s *item_2 = (esd_list_item_s *)data; @@ -539,7 +633,7 @@ static int __esd_add_launch_item(const char *event_name, const char *appid) item_of_list->pkg_id = pkg_id; app_list = g_list_find_custom(el_item->app_list_evtlaunch, - item_of_list, (GCompareFunc)esd_find_compare_by_list_item); + item_of_list, (GCompareFunc)__esd_find_compare_by_list_item); free(item_of_list); if (app_list == NULL) { _D("add new item (list item only)"); @@ -614,7 +708,7 @@ static void __esd_remove_app_list(gpointer data, gpointer user_data) } } -static int esd_remove_launch_item(gpointer data, const char *pkg_id) +static int __esd_remove_launch_item(gpointer data, const char *pkg_id) { event_launch_item *eli = (event_launch_item *)data; GList *first_list = NULL; @@ -633,7 +727,7 @@ static int esd_remove_launch_item(gpointer data, const char *pkg_id) return ES_R_OK; } -static int esd_launch_table_remove_items(const char *pkg_id) +static int __esd_launch_table_remove_items(const char *pkg_id) { GHashTableIter iter; gpointer key, value; @@ -641,7 +735,7 @@ static int esd_launch_table_remove_items(const char *pkg_id) g_hash_table_iter_init(&iter, event_launch_table); while (g_hash_table_iter_next(&iter, &key, &value)) { - if (esd_remove_launch_item(value, pkg_id) == ES_R_REMOVE) { + if (__esd_remove_launch_item(value, pkg_id) == ES_R_REMOVE) { _D("remove item itself"); g_hash_table_iter_remove(&iter); } @@ -650,7 +744,7 @@ static int esd_launch_table_remove_items(const char *pkg_id) return ES_R_OK; } -static void esd_event_launch_with_appid(gpointer data, gpointer user_data) +static void __esd_event_launch_with_appid(gpointer data, gpointer user_data) { esd_list_item_s *item = (esd_list_item_s *)data; char *app_id = item->app_id; @@ -687,18 +781,18 @@ static void esd_event_launch_with_appid(gpointer data, gpointer user_data) } } -static void esd_check_event_launch_with_eventid(gpointer data, gpointer user_data) +static void __esd_check_event_launch_with_eventid(gpointer data, gpointer user_data) { event_launch_item *el_item = (event_launch_item *)data; esd_event_param *eep = (esd_event_param *)user_data; if (strcmp(eep->event_name, (char *)el_item->event_name) == 0) { g_list_foreach(el_item->app_list_evtlaunch, - esd_event_launch_with_appid, user_data); + __esd_event_launch_with_appid, user_data); } } -static void __esd_event_handler(char *event_name, bundle *data, void *user_data) +static void __esd_launch_event_handler(char *event_name, bundle *data, void *user_data) { _D("event_name(%s)", event_name); @@ -710,6 +804,37 @@ static void __esd_event_handler(char *event_name, bundle *data, void *user_data) } if (el_item->app_list_evtlaunch != NULL) { + if (strcmp(SYS_EVENT_BATTERY_CHARGER_STATUS, event_name) == 0) { + const char *val = bundle_get_val(data, EVT_KEY_BATTERY_CHARGER_STATUS); + _D("charger val(%s)", val); + if (strcmp(EVT_VAL_BATTERY_CHARGER_CONNECTED, val) != 0) { + return; + } + } else if (strcmp(SYS_EVENT_USB_STATUS, event_name) == 0) { + const char *val = bundle_get_val(data, EVT_KEY_USB_STATUS); + _D("usb val(%s)", val); + if (strcmp(EVT_VAL_USB_CONNECTED, val) != 0) { + return; + } + } else if (strcmp(SYS_EVENT_EARJACK_STATUS, event_name) == 0) { + const char *val = bundle_get_val(data, EVT_KEY_EARJACK_STATUS); + _D("earjack val(%s)", val); + if (strcmp(EVT_VAL_EARJACK_CONNECTED, val) != 0) { + return; + } + } else if (strcmp(SYS_EVENT_INCOMMING_MSG, event_name) == 0) { + const char *msg_type = bundle_get_val(data, EVT_KEY_MSG_TYPE); + _D("msg_type(%s)", msg_type); + if (msg_type == NULL) { + return; + } + const char *msg_id = bundle_get_val(data, EVT_KEY_MSG_ID); + _D("msg_id(%s)", msg_id); + if (msg_id == NULL) { + return; + } + } + esd_event_param *eep = calloc(1, sizeof(esd_event_param)); if (!eep) { _E("memory alloc failed"); @@ -718,12 +843,53 @@ static void __esd_event_handler(char *event_name, bundle *data, void *user_data) eep->event_name = event_name; eep->event_data = data; eep->user_data = (void *)user_data; - esd_check_event_launch_with_eventid(el_item, eep); + __esd_check_event_launch_with_eventid(el_item, eep); free(eep); } } #ifdef APPFW_EVENT_SYSTEM_EARLIER_FEATURE +static void __esd_print_earlier_event(gpointer data, gpointer user_data) +{ + earlier_item *item = (earlier_item *)data; + char *event_name = (char *)item->event_name; + _D("event_name = (%s)", event_name); + + if (strcmp(event_name, SYS_EVENT_BOOT_COMPLETED) == 0) { + if (item->earlier_data) { + const char *val = bundle_get_val(item->earlier_data, EVT_KEY_BOOT_COMPLETED); + _D("boot_completed(%s)", val); + } + } else if (strcmp(event_name, SYS_EVENT_SYSTEM_SHUTDOWN) == 0) { + if (item->earlier_data) { + const char *val = bundle_get_val(item->earlier_data, EVT_KEY_SYSTEM_SHUTDOWN); + _D("shutdown(%s)", val); + } + } else if (strcmp(event_name, SYS_EVENT_LOW_MEMORY) == 0) { + if (item->earlier_data) { + const char *val = bundle_get_val(item->earlier_data, EVT_KEY_LOW_MEMORY); + _D("low_memory(%s)", val); + } + } else if (strcmp(event_name, SYS_EVENT_BATTERY_CHARGER_STATUS) == 0) { + if (item->earlier_data) { + const char *val = bundle_get_val(item->earlier_data, EVT_KEY_BATTERY_CHARGER_STATUS); + _D("charger_status(%s)", val); + } + } +} + +static void __esd_earlier_table_print_items(void) +{ + GHashTableIter iter; + gpointer key, value; + + g_hash_table_iter_init(&iter, earlier_event_table); + + while (g_hash_table_iter_next(&iter, &key, &value)) { + __esd_print_earlier_event(value, NULL); + } +} + static void __esd_earlier_event_handler(char *event_name, bundle *data, void *user_data) { _D("event_name(%s)", event_name); @@ -750,10 +916,32 @@ static void __esd_earlier_event_handler(char *event_name, bundle *data, void *us } #endif +static void __esd_event_handler(char *event_name, bundle *data, void *user_data) +{ + _D("event_name(%s)", event_name); + +#ifdef APPFW_EVENT_SYSTEM_EARLIER_FEATURE + if (__esd_check_earlier_support(event_name)) { + __esd_earlier_event_handler(event_name, data, user_data); + } +#endif + + if (__esd_check_event_launch_support(event_name)) { + __esd_launch_event_handler(event_name, data, user_data); + } +} + + static GDBusNodeInfo *introspection_data; static const gchar introspection_xml[] = "" " " +" " +" " +" " +" " +" " +" " " " " " " " @@ -801,45 +989,157 @@ static const gchar introspection_xml[] = " " ""; -static void handle_method_call(GDBusConnection *connection, - const gchar *sender, const gchar *object_path, - const gchar *interface_name, const gchar *method_name, - GVariant *parameters, GDBusMethodInvocation *invocation, - gpointer user_data) +static int __esd_get_appid_by_pid(int pid, char *app_id, int buf_size) +{ + int retval = ES_R_OK; + int ret = 0; + + if (pid > 0) { + ret = aul_app_get_appid_bypid(pid, app_id, buf_size); + if (ret != AUL_R_OK) { + _E("failed to get appid by pid"); + retval = ES_R_ERROR; + } + _D("pid(%d)-appid(%s)", pid, app_id); + } else { + _E("invalid pid"); + retval = ES_R_ERROR; + } + + return retval; +} + +static int check_user_event_sender_valid(const char *event_name, const char *app_id) +{ + char *valid_name = NULL; + char *temp_name = NULL; + char *tmp = NULL; + int retval = ES_R_OK; + int len = 0; + int valid_name_len = 0; + + temp_name = strdup(event_name); + if (temp_name == NULL) { + _E("out of memory"); + return ES_R_ENOMEM; + } + + tmp = strrchr(temp_name, '.'); + if (tmp == NULL || strlen(tmp) == 0) { + _E("invalid event name"); + FREE_AND_NULL(temp_name); + return ES_R_EINVAL; + } + len = strlen(tmp); + if (len <= 1 || len > 128) { + _E("invalid length(%d) of user-defined name"); + FREE_AND_NULL(temp_name); + return ES_R_EINVAL; + } + *tmp = '\0'; + + _D("app_id(%s), len(%d)", app_id, strlen(app_id)); + + valid_name_len = strlen(USER_EVENT_NAME_PREFIX) + strlen(app_id) + 1; + valid_name = calloc(1, valid_name_len); + if (valid_name == NULL) { + _E("memory alloc failed"); + FREE_AND_NULL(temp_name); + return ES_R_ENOMEM; + } + snprintf(valid_name, valid_name_len, "%s%s", USER_EVENT_NAME_PREFIX, app_id); + _D("valid_name(%s)", valid_name); + + if (strcmp(temp_name, valid_name) != 0) { + _E("appid misamatch"); + retval = ES_R_EINVAL; + } + + FREE_AND_NULL(temp_name); + FREE_AND_NULL(valid_name); + + return retval; +} + +static void check_sender_valid_method_call(GVariant *parameters, + GDBusMethodInvocation *invocation) { GVariant *param = NULL; int result = 0; + char *event_name = NULL; + char app_id[128] = {0, }; + int sender_pid = 0; - if (g_strcmp0(method_name, "GetTrustedPeerList") == 0) { - GVariantBuilder *builder = NULL; - GHashTableIter iter; - gpointer key, value; - char *event_name = NULL; - char app_id[256] = {0, }; - int sender_pid = 0; - int ret = 0; - char *_appid = NULL; - char *_busname = NULL; + g_variant_get(parameters, "(is)", &sender_pid, &event_name); + _D("sender_pid(%d), event_name(%s)", sender_pid, event_name); + + if (__esd_get_appid_by_pid(sender_pid, app_id, sizeof(app_id)) < 0) { + result = ES_R_ERROR; + } else { + if (check_user_event_sender_valid(event_name, app_id) < 0) { + _E("invalid sender"); + result = ES_R_EINVAL; + } else { + result = 1; + } + } - g_variant_get(parameters, "(s)", &event_name); + param = g_variant_new("(is)", result, app_id); + _D("event_name(%s), result(%d)", event_name, result); + g_dbus_method_invocation_return_value(invocation, param); +} - _D("event_name(%s)", event_name); +static void check_send_event_valid_method_call(GDBusConnection *connection, const gchar *sender, + GVariant *parameters, GDBusMethodInvocation *invocation) +{ + GVariant *param = NULL; + int result = 0; + char *event_name = NULL; + char app_id[128] = {0, }; + int sender_pid = 0; - sender_pid = __get_sender_pid(connection, sender); + g_variant_get(parameters, "(s)", &event_name); + _D("event_name(%s)", event_name); - if (sender_pid > 0) { - ret = aul_app_get_appid_bypid(sender_pid, app_id, sizeof(app_id)); - if (ret != AUL_R_OK) { - _E("failed to get appid by sender_pid"); - result = ES_R_ERROR; - goto out_get_trust; - } + sender_pid = __get_sender_pid(connection, sender); + if (__esd_get_appid_by_pid(sender_pid, app_id, sizeof(app_id)) < 0) { + result = ES_R_ERROR; + } else { + if (check_user_event_sender_valid(event_name, app_id) < 0) { + _E("invalid sender"); + result = ES_R_EINVAL; } else { - _E("failed to get sender_pid"); - result = ES_R_ERROR; - goto out_get_trust; + result = 1; } + } + + param = g_variant_new("(i)", result); + _D("event_name(%s), result(%d)", event_name, result); + g_dbus_method_invocation_return_value(invocation, param); +} + +static void get_trusted_peer_method_call(GDBusConnection *connection, const gchar *sender, + GVariant *parameters, GDBusMethodInvocation *invocation) +{ + GVariant *param = NULL; + int result = 0; + GVariantBuilder *builder = NULL; + GHashTableIter iter; + gpointer key, value; + char *event_name = NULL; + char app_id[128] = {0, }; + int sender_pid = 0; + int ret = 0; + char *_appid = NULL; + char *_busname = NULL; + g_variant_get(parameters, "(s)", &event_name); + _D("event_name(%s)", event_name); + + sender_pid = __get_sender_pid(connection, sender); + if (__esd_get_appid_by_pid(sender_pid, app_id, sizeof(app_id)) < 0) { + result = ES_R_ERROR; + } else { builder = g_variant_builder_new(G_VARIANT_TYPE("as")); g_hash_table_iter_init(&iter, trusted_busname_table); @@ -855,252 +1155,226 @@ static void handle_method_call(GDBusConnection *connection, } result = 1; -out_get_trust: - param = g_variant_new("(ias)", result, builder); - _D("result(%d)", result); - g_dbus_method_invocation_return_value(invocation, param); - if (builder) - g_variant_builder_unref(builder); - } else if (g_strcmp0(method_name, "SetupTrustedPeer") == 0) { - char *event_name = NULL; - char *destination_name = NULL; - char app_id[256] = {0, }; - int sender_pid = 0; - int ret = 0; - - g_variant_get(parameters, "(ss)", &event_name, &destination_name); + } - _D("event_name(%s), destination_name(%s)", event_name, destination_name); + param = g_variant_new("(ias)", result, builder); + _D("result(%d)", result); + g_dbus_method_invocation_return_value(invocation, param); + if (builder) { + g_variant_builder_unref(builder); + } +} - if (destination_name && destination_name[0] != '\0') { - sender_pid = __get_sender_pid(connection, sender); +static void setup_trusted_peer_method_call(GDBusConnection *connection, const gchar *sender, + GVariant *parameters, GDBusMethodInvocation *invocation) +{ + GVariant *param = NULL; + int result = 0; + char *event_name = NULL; + char *destination_name = NULL; + char app_id[128] = {0, }; + int sender_pid = 0; + int ret = 0; - if (sender_pid > 0) { - ret = aul_app_get_appid_bypid(sender_pid, app_id, sizeof(app_id)); - if (ret != AUL_R_OK) { - _E("failed to get appid by sender_pid"); - result = ES_R_ERROR; - goto out_trust; - } - } else { - _E("failed to get sender_pid"); - result = ES_R_ERROR; - goto out_trust; - } + g_variant_get(parameters, "(ss)", &event_name, &destination_name); + _D("event_name(%s), destination_name(%s)", event_name, destination_name); - ret = esd_trusted_busname_add_item(app_id, destination_name, sender_pid); + if (destination_name && destination_name[0] != '\0') { + sender_pid = __get_sender_pid(connection, sender); + if (__esd_get_appid_by_pid(sender_pid, app_id, sizeof(app_id)) < 0) { + result = ES_R_ERROR; + } else { + ret = __esd_trusted_busname_add_item(app_id, destination_name, + sender_pid); if (ret < 0) { _E("failed to add trusted busname item"); result = ES_R_ERROR; - } else - result = 1; - } else { - _E("invalid destination name"); - result = ES_R_ERROR; - } - -out_trust: - param = g_variant_new("(i)", result); - _D("event_name(%s), result(%d)", event_name, result); - g_dbus_method_invocation_return_value(invocation, param); - } else if (g_strcmp0(method_name, "CheckPrivilegeValidation") == 0) { - char *event_name = NULL; - char *privilege_name = NULL; - char app_id[256] = {0, }; - int sender_pid = 0; - int ret = 0; - - g_variant_get(parameters, "(s)", &event_name); - - __esd_check_privilege_name(event_name, &privilege_name); - - _D("event_name(%s), privilege_name(%s)", event_name, privilege_name); - - if (privilege_name) { - sender_pid = __get_sender_pid(connection, sender); - - if (sender_pid > 0) { - ret = aul_app_get_appid_bypid(sender_pid, app_id, sizeof(app_id)); - if (ret != AUL_R_OK) { - _E("failed to get appid by sender_pid"); - result = ES_R_ERROR; - goto out_priv; - } } else { - _E("failed to get sender_pid"); - result = ES_R_ERROR; - goto out_priv; - } - - if (__esd_check_valid_privilege(app_id, privilege_name)) { result = 1; - } else { - result = ES_R_EINVAL; } - } else { - result = 1; } -out_priv: - param = g_variant_new("(i)", result); - _D("event_name(%s), result(%d)", event_name, result); - g_dbus_method_invocation_return_value(invocation, param); - } else if (g_strcmp0(method_name, "CheckUserSendValidation") == 0) { - char *event_name = NULL; - char app_id[256] = {0, }; - char valid_name[1024]; - int sender_pid = 0; - int ret = 0; - int len = 0; + } else { + _E("invalid destination name"); + result = ES_R_ERROR; + } - g_variant_get(parameters, "(s)", &event_name); + param = g_variant_new("(i)", result); + _D("event_name(%s), result(%d)", event_name, result); + g_dbus_method_invocation_return_value(invocation, param); +} - _D("event_name(%s)", event_name); +static void check_privilege_valid_method_call(GDBusConnection *connection, const gchar *sender, + GVariant *parameters, GDBusMethodInvocation *invocation) +{ + GVariant *param = NULL; + int result = 0; + char *event_name = NULL; + char *privilege_name = NULL; + char app_id[128] = {0, }; + int sender_pid = 0; - sender_pid = __get_sender_pid(connection, sender); + g_variant_get(parameters, "(s)", &event_name); + __esd_check_privilege_name(event_name, &privilege_name); + _D("event_name(%s), privilege_name(%s)", event_name, privilege_name); - if (sender_pid > 0) { - ret = aul_app_get_appid_bypid(sender_pid, app_id, sizeof(app_id)); - if (ret != AUL_R_OK) { - _E("failed to get appid by sender_pid"); - result = ES_R_ERROR; - goto out_send; - } - } else { - _E("failed to get sender_pid"); + if (privilege_name) { + sender_pid = __get_sender_pid(connection, sender); + if (__esd_get_appid_by_pid(sender_pid, app_id, sizeof(app_id)) < 0) { result = ES_R_ERROR; - goto out_send; - } - - snprintf(valid_name, 1024, "%s%s.", USER_EVENT_NAME_PREFIX, app_id); - len = strlen(valid_name); - - _D("valid_name(%s)", valid_name); - - if (strncmp(event_name, valid_name, len) != 0) { - _E("appid misamatch"); - result = ES_R_EINVAL; - goto out_send; } else { - len = strlen(event_name) - len; - if (len < 1 || len > 127) { - _E("Invalid Length of user-defined name"); + if (__esd_check_valid_privilege(app_id, privilege_name)) { + result = 1; + } else { result = ES_R_EINVAL; - goto out_send; } } - + } else { result = 1; -out_send: - param = g_variant_new("(i)", result); - _D("event_name(%s), result(%d)", event_name, result); - g_dbus_method_invocation_return_value(invocation, param); - } else if (g_strcmp0(method_name, "RequestEventLaunch") == 0) { - char *event_name = NULL; - bundle_raw *raw = NULL; - bundle *b = NULL; - int len = 0; - - g_variant_get(parameters, "(ssi)", &event_name, &raw, &len); - - b = bundle_decode(raw, len); - __esd_event_handler(event_name, b, NULL); - bundle_free(b); + } - result = 1; + param = g_variant_new("(i)", result); + _D("event_name(%s), result(%d)", event_name, result); + g_dbus_method_invocation_return_value(invocation, param); +} - param = g_variant_new("(i)", result); - _D("event_name(%s), result(%d)", event_name, result); - g_dbus_method_invocation_return_value(invocation, param); - } else if (g_strcmp0(method_name, "RequestTrustedEventLaunch") == 0) { - char app_id[256] = {0, }; - int sender_pid = 0; - int ret = 0; - char *event_name = NULL; - bundle_raw *raw = NULL; - bundle *b = NULL; - int len = 0; +static void request_sending_event_method_call(GDBusConnection *connection, const gchar *sender, + GVariant *parameters, GDBusMethodInvocation *invocation) +{ + GVariant *param = NULL; + int result = 0; + char *event_name = NULL; + bundle_raw *raw = NULL; + bundle *b = NULL; + int len = 0; + const char *access_rule = NULL; + const char *check_object = NULL; + char app_id[128] = {0, }; + char *pkg_id = NULL; + int sender_pid = 0; + int sender_uid = -1; + int visibility = 0; + int send_flag = 0; + int ret = 0; - g_variant_get(parameters, "(ssi)", &event_name, &raw, &len); + g_variant_get(parameters, "(ssi)", &event_name, &raw, &len); + _D("event_name(%s)", event_name); - _D("requested trusted-event launch"); + if (!__esd_is_sending_allowed_event(event_name)) { + /* no effect */ + _E("not allowed"); + result = 1; + goto end; + } - sender_pid = __get_sender_pid(connection, sender); + sender_uid = __get_sender_uid(connection, sender); + _D("uid(%d), getuid(%d)", sender_uid, getuid()); + if (sender_uid >= 0 && sender_uid <= getuid()) { + send_flag = 1; + goto end; + } - if (sender_pid > 0) { - ret = aul_app_get_appid_bypid(sender_pid, app_id, sizeof(app_id)); - if (ret != AUL_R_OK) { - _E("failed to get appid by sender_pid"); + /* TODO(jongmyeong.ko) */ + /* + sender_pid = __get_sender_pid(connection, sender); + if (sender_pid > 0) { + if (__esd_get_appid_by_pid(sender_pid, app_id, sizeof(app_id)) < 0) { + result = ES_R_ERROR; + } else { + if (__esd_get_pkgid_by_appid(app_id, &pkg_id) < 0) { result = ES_R_ERROR; - goto out_trust_launch; } - } else { - _E("failed to get sender_pid"); + } + } + + if (pkg_id) { + if (__esd_get_visibility_from_cert_svc(pkg_id, &visibility) < 0) { result = ES_R_ERROR; - goto out_trust_launch; + } else { + if (visibility == CERT_SVC_VISIBILITY_PLATFORM) { + _D("platfrom package"); + send_flag = 1; + } } + FREE_AND_NULL(pkg_id); + } + */ - _D("from_appid(%s)", app_id); +end: + if (send_flag) { b = bundle_decode(raw, len); - __esd_event_handler(event_name, b, app_id); + eventsystem_send_system_event(event_name, b); bundle_free(b); - result = 1; -out_trust_launch: - param = g_variant_new("(i)", result); - _D("event_name(%s), result(%d)", event_name, result); - g_dbus_method_invocation_return_value(invocation, param); - } else if (g_strcmp0(method_name, "RequestSendingEvent") == 0) { - char *event_name = NULL; - bundle_raw *raw = NULL; - bundle *b = NULL; - int len = 0; - - g_variant_get(parameters, "(ssi)", &event_name, &raw, &len); + } - b = bundle_decode(raw, len); - eventsystem_send_system_event(event_name, b); - bundle_free(b); + param = g_variant_new("(i)", result); - result = 1; - param = g_variant_new("(i)", result); + _D("event_name(%s), result(%d)", event_name, result); + g_dbus_method_invocation_return_value(invocation, param); +} - _D("event_name(%s), result(%d)", event_name, result); - g_dbus_method_invocation_return_value(invocation, param); #ifdef APPFW_EVENT_SYSTEM_EARLIER_FEATURE - } else if (g_strcmp0(method_name, "GetEarlierData") == 0) { - char *event_name = NULL; - bundle *b = NULL; - bundle_raw *raw = NULL; - int len = 0; +static void get_earlier_data_method_call(GVariant *parameters, GDBusMethodInvocation *invocation) +{ + GVariant *param = NULL; + int result = 0; + char *event_name = NULL; + bundle *b = NULL; + bundle_raw *raw = NULL; + int len = 0; - g_variant_get(parameters, "(s)", &event_name); + g_variant_get(parameters, "(s)", &event_name); - if (event_name && strlen(event_name) > 0) { - _D("event_name(%s)", event_name); - result = ES_R_OK; - } else { - _E("invalid appid(%s)", event_name); - result = ES_R_ERROR; - } + if (event_name && strlen(event_name) > 0) { + _D("event_name(%s)", event_name); + result = ES_R_OK; + } else { + _E("invalid event_name(%s)", event_name); + result = ES_R_ERROR; + } - earlier_item *item = - (earlier_item *)g_hash_table_lookup(earlier_event_table, event_name); + earlier_item *item = + (earlier_item *)g_hash_table_lookup(earlier_event_table, event_name); - if (item != NULL) { - if (item->earlier_data) { - b = bundle_dup(item->earlier_data); - bundle_add_str(b, "is_earlier_data", "true"); - bundle_encode(b, &raw, &len); - bundle_free(b); - } + if (item != NULL) { + if (item->earlier_data) { + b = bundle_dup(item->earlier_data); + bundle_add_str(b, "is_earlier_data", "true"); + bundle_encode(b, &raw, &len); + bundle_free(b); } + } - param = g_variant_new("(iis)", result, len, raw); + param = g_variant_new("(iis)", result, len, raw); - _D("result(%d), len(%d)", result, len); - g_dbus_method_invocation_return_value(invocation, param); + _D("result(%d), len(%d)", result, len); + g_dbus_method_invocation_return_value(invocation, param); + + bundle_free_encoded_rawdata(&raw); +} +#endif - bundle_free_encoded_rawdata(&raw); +static void handle_method_call(GDBusConnection *connection, + const gchar *sender, const gchar *object_path, + const gchar *interface_name, const gchar *method_name, + GVariant *parameters, GDBusMethodInvocation *invocation, + gpointer user_data) +{ + if (g_strcmp0(method_name, "CheckSenderValidation") == 0) { + check_sender_valid_method_call(parameters, invocation); + } else if (g_strcmp0(method_name, "GetTrustedPeerList") == 0) { + get_trusted_peer_method_call(connection, sender, parameters, invocation); + } else if (g_strcmp0(method_name, "SetupTrustedPeer") == 0) { + setup_trusted_peer_method_call(connection, sender, parameters, invocation); + } else if (g_strcmp0(method_name, "CheckPrivilegeValidation") == 0) { + check_privilege_valid_method_call(connection, sender, parameters, invocation); + } else if (g_strcmp0(method_name, "CheckUserSendValidation") == 0) { + check_send_event_valid_method_call(connection, sender, parameters, invocation); + } else if (g_strcmp0(method_name, "RequestSendingEvent") == 0) { + request_sending_event_method_call(connection, sender, parameters, invocation); +#ifdef APPFW_EVENT_SYSTEM_EARLIER_FEATURE + } else if (g_strcmp0(method_name, "GetEarlierData") == 0) { + get_earlier_data_method_call(parameters, invocation); #endif } } @@ -1114,7 +1388,7 @@ static const GDBusInterfaceVTable interface_vtable = { static void on_bus_acquired(GDBusConnection *connection, const gchar *name, gpointer user_data) { - _D("on_bus_acquired(%s)", name); + _I("on_bus_acquired(%s)", name); guint reg_id = 0; GError *error = NULL; @@ -1133,7 +1407,7 @@ static void on_bus_acquired(GDBusConnection *connection, static void on_name_acquired(GDBusConnection *connection, const gchar *name, gpointer user_data) { - _D("on_name_acquired(%s)", name); + _I("on_name_acquired(%s)", name); __esd_check_trusted_events(connection, "ListNames"); __esd_check_trusted_events(connection, "ListActivatableNames"); @@ -1143,13 +1417,15 @@ static void on_name_acquired(GDBusConnection *connection, eventsystem_send_system_event(SYS_EVENT_ESD_STATUS, b); bundle_free(b); - esd_trusted_busname_print_items(); + __esd_register_vconf_callbacks(); + + __esd_trusted_busname_print_items(); } static void on_name_lost(GDBusConnection *connection, const gchar *name, gpointer user_data) { - _D("on_name_lost(%s)", name); + _E("on_name_lost(%s)", name); } static int __esd_before_loop(void) @@ -1193,6 +1469,20 @@ static int __esd_before_loop(void) EVT_VAL_BOOT_COMPLETED_TRUE); close(fd); } + } else if (strcmp(event_name, SYS_EVENT_SYSTEM_SHUTDOWN) == 0) { + int val; + ret = vconf_get_int(VCONFKEY_SYSMAN_POWER_OFF_STATUS, &val); + if (ret != VCONF_OK) { + _E("failed to get power_off status (%d)", ret); + } else { + if (val == VCONFKEY_SYSMAN_POWER_OFF_DIRECT || + val == VCONFKEY_SYSMAN_POWER_OFF_RESTART) { + /* power-off requested */ + item->earlier_data = bundle_create(); + bundle_add_str(item->earlier_data, EVT_KEY_SYSTEM_SHUTDOWN, + EVT_VAL_SYSTEM_SHUTDOWN_TRUE); + } + } } else if (strcmp(event_name, SYS_EVENT_LOW_MEMORY) == 0) { int status; ret = vconf_get_int(VCONFKEY_SYSMAN_LOW_MEMORY, &status); @@ -1210,19 +1500,58 @@ static int __esd_before_loop(void) bundle_add_str(item->earlier_data, EVT_KEY_LOW_MEMORY, EVT_VAL_MEMORY_NORMAL); } + } else if (strcmp(event_name, SYS_EVENT_BATTERY_CHARGER_STATUS) == 0) { + int charger_status; + int charge_now; + ret = vconf_get_int(VCONFKEY_SYSMAN_CHARGER_STATUS, &charger_status); + if (ret != VCONF_OK) { + _E("failed to get charger_status (%d)", ret); + } else { + ret = vconf_get_int(VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW, &charge_now); + if (ret != VCONF_OK) { + _E("failed to get charge_now (%d)", ret); + } + } + + if (ret == VCONF_OK) { + item->earlier_data = bundle_create(); + if (charger_status == VCONFKEY_SYSMAN_CHARGER_CONNECTED) { + if (charge_now == 0) { + bundle_add_str(item->earlier_data, + EVT_KEY_BATTERY_CHARGER_STATUS, + EVT_VAL_BATTERY_CHARGER_DISCHARGING); + } else { + bundle_add_str(item->earlier_data, + EVT_KEY_BATTERY_CHARGER_STATUS, + EVT_VAL_BATTERY_CHARGER_CHARGING); + } + } else { + bundle_add_str(item->earlier_data, + EVT_KEY_BATTERY_CHARGER_STATUS, + EVT_VAL_BATTERY_CHARGER_DISCONNECTED); + } + } } - g_hash_table_insert(earlier_event_table, event_name, item); - eventsystem_register_event(item->event_name, &subscription_id, - (eventsystem_handler)__esd_earlier_event_handler, NULL); + eventsystem_register_event(event_name, &subscription_id, + (eventsystem_handler)__esd_event_handler, NULL); if (subscription_id == 0) { - _E("signal subscription error, event_name(%s)", item->event_name); + _E("signal subscription error, event_name(%s)", event_name); + if (item->earlier_data) + bundle_free(item->earlier_data); + free(item->event_name); + free(item); + return ES_R_ERROR; } else { item->reg_id = subscription_id; } + + g_hash_table_insert(earlier_event_table, event_name, item); } + + __esd_earlier_table_print_items(); #endif event_launch_table = g_hash_table_new(g_str_hash, g_str_equal); @@ -1233,7 +1562,7 @@ static int __esd_before_loop(void) _E("pkgmgrinfo_appinfo_get_usr_installed_list error"); return ES_R_ERROR; } - esd_launch_table_print_items(); + __esd_launch_table_print_items(); trusted_busname_table = g_hash_table_new(g_str_hash, g_str_equal); @@ -1262,10 +1591,12 @@ static int __esd_before_loop(void) return ES_R_ERROR; } + _I("esd before_loop done"); + return ES_R_OK; } -static void esd_pkgmgr_event_free(esd_pkgmgr_event *pkg_event) +static void __esd_pkgmgr_event_free(esd_pkgmgr_event *pkg_event) { pkg_event->type = UNKNOWN; if (pkg_event->pkgid) { @@ -1289,7 +1620,9 @@ static int __esd_appcontrol_cb(const char *operation, event_name = strdup(&uri[8]); if (event_name) { _D("appid(%s), event_name(%s)", appid, event_name); - if (!__esd_check_app_privileged_event(appid, event_name)) { + if (!__esd_check_event_launch_support(event_name)) { + _E("failed to add item (not support event)"); + } else if (!__esd_check_app_privileged_event(appid, event_name)) { _E("failed to add item (no privilege)"); } else { if (__esd_add_launch_item(event_name, appid)) { @@ -1333,13 +1666,13 @@ static int __esd_add_appinfo_handler(const pkgmgrinfo_appinfo_h handle, void *da _E("failed to get appcontrol info"); return ES_R_ERROR; } - esd_launch_table_print_items(); + __esd_launch_table_print_items(); } return ES_R_OK; } -static int esd_pkgmgr_event_callback(uid_t uid, int req_id, const char *pkg_type, +static int __esd_pkgmgr_event_callback(uid_t uid, int req_id, const char *pkg_type, const char *pkgid, const char *key, const char *val, const void *pmsg, void *data) { @@ -1362,7 +1695,7 @@ static int esd_pkgmgr_event_callback(uid_t uid, int req_id, const char *pkg_type pkg_event->type = UPDATE; } else { _D("val(%s) start", val); - esd_pkgmgr_event_free(pkg_event); + __esd_pkgmgr_event_free(pkg_event); } } else if (strcmp(key, "end") == 0 && strcmp(val, "ok") == 0) { if (pkg_event->type == INSTALL || pkg_event->type == UPDATE) { @@ -1370,34 +1703,34 @@ static int esd_pkgmgr_event_callback(uid_t uid, int req_id, const char *pkg_type ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, uid, &handle); if (ret < 0) { _E("failed to get pkginfo"); - esd_pkgmgr_event_free(pkg_event); + __esd_pkgmgr_event_free(pkg_event); return 0; } ret = pkgmgrinfo_appinfo_get_list(handle, PMINFO_ALL_APP, __esd_add_appinfo_handler, NULL); if (ret < 0) { _E("failed to get appinfo"); - esd_pkgmgr_event_free(pkg_event); + __esd_pkgmgr_event_free(pkg_event); return 0; } ret = pkgmgrinfo_pkginfo_destroy_pkginfo(handle); if (ret < 0) { _E("failed to destroy pkginfo"); - esd_pkgmgr_event_free(pkg_event); + __esd_pkgmgr_event_free(pkg_event); return 0; } } else if (pkg_event->type == UNINSTALL) { _D("uninstall end (ok)"); - esd_launch_table_remove_items(pkgid); - esd_launch_table_print_items(); + __esd_launch_table_remove_items(pkgid); + __esd_launch_table_print_items(); } - esd_pkgmgr_event_free(pkg_event); + __esd_pkgmgr_event_free(pkg_event); } else if (strcmp(key, "end") == 0 && strcmp(val, "fail") == 0) { _E("pkg_event(%d) falied", pkg_event->type); - esd_pkgmgr_event_free(pkg_event); + __esd_pkgmgr_event_free(pkg_event); } else { if (strcmp(key, "install_percent") != 0) { - esd_pkgmgr_event_free(pkg_event); + __esd_pkgmgr_event_free(pkg_event); } } @@ -1460,7 +1793,7 @@ static int __esd_init() return ES_R_ENOMEM; } - req_id = pkgmgr_client_listen_status(client, esd_pkgmgr_event_callback, pkg_event); + req_id = pkgmgr_client_listen_status(client, __esd_pkgmgr_event_callback, pkg_event); if (req_id < 0) { _E("pkgmgr client listen failed"); ret = pkgmgr_client_free(client); @@ -1472,12 +1805,12 @@ static int __esd_init() s_info.client = client; - _D("ESD init done\n"); + _I("esd init done"); return 0; } -static void esd_remove_app_list(gpointer data, gpointer user_data) +static void __esd_remove_esd_list_item(gpointer data, gpointer user_data) { esd_list_item_s *item = (esd_list_item_s *)data; @@ -1485,7 +1818,7 @@ static void esd_remove_app_list(gpointer data, gpointer user_data) free(item->pkg_id); } -static void esd_finalize(void) +static void __esd_finalize(void) { gpointer key, value; int ret = 0; @@ -1544,7 +1877,7 @@ static void esd_finalize(void) eventsystem_unregister_event(el_item->reg_id); free(el_item->event_name); g_list_foreach(el_item->app_list_evtlaunch, - esd_remove_app_list, NULL); + __esd_remove_esd_list_item, NULL); g_list_free(el_item->app_list_evtlaunch); free(el_item); } else { @@ -1571,17 +1904,17 @@ static void esd_finalize(void) int main(int argc, char *argv[]) { - _D("event system daemon : main()\n"); + _I("event system daemon : main()"); if (__esd_init() != 0) { - _E("ESD Initialization failed!\n"); + _E("ESD Initialization failed!"); assert(0); return ES_R_ERROR; } if (__esd_before_loop() < 0) { - _E("ESD failed!\n"); - esd_finalize(); + _E("ESD failed!"); + __esd_finalize(); assert(0); return ES_R_ERROR; } @@ -1590,7 +1923,7 @@ int main(int argc, char *argv[]) _E("shutdown"); - esd_finalize(); + __esd_finalize(); ecore_shutdown(); diff --git a/src/esd_system_event.c b/src/esd_system_event.c new file mode 100644 index 0000000..5579ac5 --- /dev/null +++ b/src/esd_system_event.c @@ -0,0 +1,603 @@ +#include +#include +#include +#include +#include +#include +#include + +#include "eventsystem_daemon.h" + +/* table item : sent system-event by esd */ +static GHashTable *esd_sent_table; + +typedef struct __esd_sent_table_item { + char *event_name; + bundle *event_data; +} esd_sent_item; + +struct esd_vconf_handler { + const char *key; + void (*esd_vconfcb_fn) (keynode_t *node, void *user_data); +}; + +static int __esd_event_data_compare(bundle *b1, bundle *b2, const char *key) +{ + int ret = 0; + int tmp1 = 0; + int tmp2 = 0; + char *str1 = NULL; + char *str2 = NULL; + + if (bundle_get_count(b1) == bundle_get_count(b2)) { + tmp1 = bundle_get_str(b1, key, &str1); + tmp2 = bundle_get_str(b2, key, &str2); + if (tmp1 == BUNDLE_ERROR_NONE && tmp2 == BUNDLE_ERROR_NONE) { + if (strcmp(str1, str2) != 0) { + _D("new event_data : value check"); + ret = 1; + } + } + } else { + _D("new event_data : bundle_count check"); + ret = 1; + } + + if (ret == 0) { + _D("same event_data"); + } + + return ret; +} + +static int __esd_send_system_event(const char *event_name, bundle *b, const char *key) +{ + int ret = ES_R_OK; + + esd_sent_item *item = + (esd_sent_item *)g_hash_table_lookup(esd_sent_table, event_name); + + if (item && __esd_event_data_compare(item->event_data, b, key) == 0) { + _D("skip send: same with previous data"); + } else { + ret = eventsystem_send_system_event(event_name, b); + if (ret != ES_R_OK) { + _E("failed to send event"); + goto out; + } + + if (item) { + bundle_free(item->event_data); + item->event_data = bundle_dup(b); + } else { + item = calloc(1, sizeof(esd_sent_item)); + if (item == NULL) { + _E("memory alloc failed"); + ret = ES_R_ERROR; + goto out; + } + item->event_name = strdup(event_name); + if (item->event_name == NULL) { + _E("out of memory"); + FREE_AND_NULL(item); + ret = ES_R_ERROR; + goto out; + } + item->event_data = bundle_dup(b); + } + + g_hash_table_insert(esd_sent_table, item->event_name, item); + } + +out: + return ret; +} + +static void __esd_vconfcb_location_use_mylocation(keynode_t *node, void *user_data) +{ + int ret = 0; + int enabled = 0; + bundle *b = NULL; + const char *key = NULL; + const char *val = NULL; + + _D("vconfcb called"); + + ret = vconf_get_int(VCONFKEY_LOCATION_USE_MY_LOCATION, &enabled); + if (ret != VCONF_OK) { + _E("failed to get vconf (%d)", ret); + return; + } + + key = EVT_KEY_LOCATION_ENABLE_STATE; + + if (enabled) { + val = EVT_VAL_LOCATION_ENABLED; + } else { + val = EVT_VAL_LOCATION_DISABLED; + } + + b = bundle_create(); + bundle_add_str(b, key, val); + + if (__esd_send_system_event(SYS_EVENT_LOCATION_ENABLE_STATE, b, key) != ES_R_OK) { + _E("failed to send event"); + } + + if (b) { + bundle_free(b); + } +} + +static void __esd_vconfcb_location_enabled(keynode_t *node, void *user_data) +{ + int ret = 0; + int enabled = 0; + bundle *b = NULL; + const char *key = NULL; + const char *val = NULL; + + _D("vconfcb called"); + + ret = vconf_get_int(VCONFKEY_LOCATION_ENABLED, &enabled); + if (ret != VCONF_OK) { + _E("failed to get vconf (%d)", ret); + return; + } + + key = EVT_KEY_GPS_ENABLE_STATE; + + if (enabled) { + val = EVT_VAL_GPS_ENABLED; + } else { + val = EVT_VAL_GPS_DISABLED; + } + + b = bundle_create(); + bundle_add_str(b, key, val); + + if (__esd_send_system_event(SYS_EVENT_GPS_ENABLE_STATE, b, key) != ES_R_OK) { + _E("failed to send event"); + } + + if (b) { + bundle_free(b); + } +} + +static void __esd_vconfcb_location_network_enabled(keynode_t *node, void *user_data) +{ + int ret = 0; + int enabled = 0; + bundle *b = NULL; + const char *key = NULL; + const char *val = NULL; + + _D("vconfcb called"); + + ret = vconf_get_int(VCONFKEY_LOCATION_NETWORK_ENABLED, &enabled); + if (ret != VCONF_OK) { + _E("failed to get vconf (%d)", ret); + return; + } + + key = EVT_KEY_NPS_ENABLE_STATE; + + if (enabled) { + val = EVT_VAL_NPS_ENABLED; + } else { + val = EVT_VAL_NPS_DISABLED; + } + + b = bundle_create(); + bundle_add_str(b, key, val); + + if (__esd_send_system_event(SYS_EVENT_NPS_ENABLE_STATE, b, key) != ES_R_OK) { + _E("failed to send event"); + } + + if (b) { + bundle_free(b); + } +} + +static void __esd_vconfcb_language_set(keynode_t *node, void *user_data) +{ + char *str = 0; + bundle *b = NULL; + const char *key = NULL; + + _D("vconfcb called"); + + str = vconf_get_str(VCONFKEY_LANGSET); + if (str == NULL) { + _E("failed to get vconf str"); + return; + } + + key = EVT_KEY_LANGUAGE_SET; + + b = bundle_create(); + bundle_add_str(b, key, str); + + if (__esd_send_system_event(SYS_EVENT_LANGUAGE_SET, b, key) != ES_R_OK) { + _E("failed to send event"); + } + + if (b) { + bundle_free(b); + } +} + +static void __esd_vconfcb_hour_format(keynode_t *node, void *user_data) +{ + int ret = 0; + int hours = 0; + bundle *b = NULL; + const char *key = NULL; + const char *val = NULL; + + _D("vconfcb called"); + + ret = vconf_get_int(VCONFKEY_REGIONFORMAT_TIME1224, &hours); + if (ret != VCONF_OK) { + _E("failed to get vconf (%d)", ret); + return; + } + + key = EVT_KEY_HOUR_FORMAT; + + if (hours == VCONFKEY_TIME_FORMAT_24) + val = EVT_VAL_HOURFORMAT_24; + else + val = EVT_VAL_HOURFORMAT_12; + + b = bundle_create(); + bundle_add_str(b, key, val); + + if (__esd_send_system_event(SYS_EVENT_HOUR_FORMAT, b, key) != ES_R_OK) { + _E("failed to send event"); + } + + if (b) { + bundle_free(b); + } +} + +static void __esd_vconfcb_region_format(keynode_t *node, void *user_data) +{ + char *str = 0; + bundle *b = NULL; + const char *key = NULL; + + _D("vconfcb called"); + + str = vconf_get_str(VCONFKEY_REGIONFORMAT); + if (str == NULL) { + _E("failed to get vconf str"); + return; + } + + key = EVT_KEY_REGION_FORMAT; + + b = bundle_create(); + bundle_add_str(b, key, str); + + if (__esd_send_system_event(SYS_EVENT_REGION_FORMAT, b, key) != ES_R_OK) { + _E("failed to send event"); + } + + if (b) { + bundle_free(b); + } +} + +static void __esd_vconfcb_vibration_status(keynode_t *node, void *user_data) +{ + int ret = 0; + int vibration_on = 0; + int sound_on = 0; + bundle *b = NULL; + char *key = NULL; + char *val = NULL; + + _D("vconfcb called"); + + ret = vconf_get_bool(VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL, &vibration_on); + if (ret != VCONF_OK) { + _E("failed to get vconf (%d)", ret); + return; + } + + ret = vconf_get_bool(VCONFKEY_SETAPPL_SOUND_STATUS_BOOL, &sound_on); + if (ret != VCONF_OK) { + _E("failed to get vconf (%d)", ret); + return; + } + + if (vibration_on) { + key = EVT_KEY_VIBRATION_STATE; + val = EVT_VAL_VIBRATION_ON; + b = bundle_create(); + bundle_add_str(b, key, val); + if (__esd_send_system_event(SYS_EVENT_VIBRATION_STATE, b, key) != ES_R_OK) { + _E("failed to send event"); + } + if (b) { + bundle_free(b); + } + + key = EVT_KEY_SILENT_MODE; + val = EVT_VAL_SILENTMODE_OFF; + b = bundle_create(); + bundle_add_str(b, key, val); + if (__esd_send_system_event(SYS_EVENT_SILENT_MODE, b, key) != ES_R_OK) { + _E("failed to send event"); + } + if (b) { + bundle_free(b); + } + } else { + key = EVT_KEY_VIBRATION_STATE; + val = EVT_VAL_VIBRATION_OFF; + b = bundle_create(); + bundle_add_str(b, key, val); + if (__esd_send_system_event(SYS_EVENT_VIBRATION_STATE, b, key) != ES_R_OK) { + _E("failed to send event"); + } + if (b) { + bundle_free(b); + } + + if (!sound_on) { + key = EVT_KEY_SILENT_MODE; + val = EVT_VAL_SILENTMODE_ON; + b = bundle_create(); + bundle_add_str(b, key, val); + if (__esd_send_system_event(SYS_EVENT_SILENT_MODE, b, key) != ES_R_OK) { + _E("failed to send event"); + } + if (b) { + bundle_free(b); + } + } + } +} + +static void __esd_vconfcb_sound_status(keynode_t *node, void *user_data) +{ + int ret = 0; + int vibration_on = 0; + int sound_on = 0; + bundle *b = NULL; + char *key = NULL; + char *val = NULL; + + _D("vconfcb called"); + + ret = vconf_get_bool(VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL, &vibration_on); + if (ret != VCONF_OK) { + _E("failed to get vconf (%d)", ret); + return; + } + + ret = vconf_get_bool(VCONFKEY_SETAPPL_SOUND_STATUS_BOOL, &sound_on); + if (ret != VCONF_OK) { + _E("failed to get vconf (%d)", ret); + return; + } + + if (sound_on) { + key = EVT_KEY_VIBRATION_STATE; + val = EVT_VAL_VIBRATION_OFF; + b = bundle_create(); + bundle_add_str(b, key, val); + if (__esd_send_system_event(SYS_EVENT_VIBRATION_STATE, b, key) != ES_R_OK) { + _E("failed to send event"); + } + if (b) { + bundle_free(b); + } + + key = EVT_KEY_SILENT_MODE; + val = EVT_VAL_SILENTMODE_OFF; + b = bundle_create(); + bundle_add_str(b, key, val); + if (__esd_send_system_event(SYS_EVENT_SILENT_MODE, b, key) != ES_R_OK) { + _E("failed to send event"); + } + if (b) { + bundle_free(b); + } + } else { + if (!vibration_on) { + key = EVT_KEY_SILENT_MODE; + val = EVT_VAL_SILENTMODE_ON; + b = bundle_create(); + bundle_add_str(b, key, val); + if (__esd_send_system_event(SYS_EVENT_SILENT_MODE, b, key) != ES_R_OK) { + _E("failed to send event"); + } + if (b) { + bundle_free(b); + } + } + } +} + +static void __esd_vconfcb_auto_rotate(keynode_t *node, void *user_data) +{ + int ret = 0; + int enabled = 0; + bundle *b = NULL; + const char *key = NULL; + const char *val = NULL; + + _D("vconfcb called"); + + ret = vconf_get_bool(VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL, &enabled); + if (ret != VCONF_OK) { + _E("failed to get vconf (%d)", ret); + return; + } + + key = EVT_KEY_SCREEN_AUTOROTATE_STATE; + + if (enabled) + val = EVT_VAL_SCREEN_AUTOROTATE_ON; + else + val = EVT_VAL_SCREEN_AUTOROTATE_OFF; + + b = bundle_create(); + bundle_add_str(b, key, val); + + if (__esd_send_system_event(SYS_EVENT_SCREEN_AUTOROTATE_STATE, b, key) != ES_R_OK) { + _E("failed to send event"); + } + + if (b) { + bundle_free(b); + } +} + +static void __esd_vconfcb_mobiledata_state(keynode_t *node, void *user_data) +{ + int ret = 0; + int enabled = 0; + bundle *b = NULL; + const char *key = NULL; + const char *val = NULL; + + _D("vconfcb called"); + + ret = vconf_get_bool(VCONFKEY_3G_ENABLE, &enabled); + if (ret != VCONF_OK) { + _E("failed to get vconf (%d)", ret); + return; + } + + key = EVT_KEY_MOBILE_DATA_STATE; + + if (enabled) + val = EVT_VAL_MOBILE_DATA_ON; + else + val = EVT_VAL_MOBILE_DATA_OFF; + + b = bundle_create(); + bundle_add_str(b, key, val); + + if (__esd_send_system_event(SYS_EVENT_MOBILE_DATA_STATE, b, key) != ES_R_OK) { + _E("failed to send event"); + } + + if (b) { + bundle_free(b); + } +} + +static void __esd_vconfcb_roaming_state(keynode_t *node, void *user_data) +{ + int ret = 0; + int enabled = 0; + bundle *b = NULL; + const char *key = NULL; + const char *val = NULL; + + _D("vconfcb called"); + + ret = vconf_get_bool(VCONFKEY_SETAPPL_STATE_DATA_ROAMING_BOOL, &enabled); + if (ret != VCONF_OK) { + _E("failed to get vconf (%d)", ret); + return; + } + + key = EVT_KEY_DATA_ROAMING_STATE; + + if (enabled) + val = EVT_VAL_DATA_ROAMING_ON; + else + val = EVT_VAL_DATA_ROAMING_OFF; + + b = bundle_create(); + bundle_add_str(b, key, val); + + if (__esd_send_system_event(SYS_EVENT_DATA_ROAMING_STATE, b, key) != ES_R_OK) { + _E("failed to send event"); + } + + if (b) { + bundle_free(b); + } +} + +static void __esd_vconfcb_font_set(keynode_t *node, void *user_data) +{ + char *str = 0; + bundle *b = NULL; + const char *key = NULL; + + _D("vconfcb called"); + + str = vconf_get_str(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_NAME); + if (str == NULL) { + _E("failed to get vconf str"); + return; + } + + key = EVT_KEY_FONT_SET; + + b = bundle_create(); + bundle_add_str(b, key, str); + + if (__esd_send_system_event(SYS_EVENT_FONT_SET, b, key) != ES_R_OK) { + _E("failed to send event"); + } + + if (b) { + bundle_free(b); + } +} + +static struct esd_vconf_handler vconf_callbacks[] = { + {VCONFKEY_LOCATION_USE_MY_LOCATION, __esd_vconfcb_location_use_mylocation}, + {VCONFKEY_LOCATION_ENABLED, __esd_vconfcb_location_enabled}, + {VCONFKEY_LOCATION_NETWORK_ENABLED, __esd_vconfcb_location_network_enabled}, + {VCONFKEY_LANGSET, __esd_vconfcb_language_set}, + {VCONFKEY_REGIONFORMAT_TIME1224, __esd_vconfcb_hour_format}, + {VCONFKEY_REGIONFORMAT, __esd_vconfcb_region_format}, + {VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL, __esd_vconfcb_vibration_status}, + {VCONFKEY_SETAPPL_SOUND_STATUS_BOOL, __esd_vconfcb_sound_status}, + {VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL, __esd_vconfcb_auto_rotate}, + {VCONFKEY_3G_ENABLE, __esd_vconfcb_mobiledata_state}, + {VCONFKEY_SETAPPL_STATE_DATA_ROAMING_BOOL, __esd_vconfcb_roaming_state}, + {VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_NAME, __esd_vconfcb_font_set}, +}; + +static int vconfcbs_size = sizeof(vconf_callbacks)/sizeof(struct esd_vconf_handler); + +int __esd_register_vconf_callbacks(void) +{ + int i = 0; + int ret = 0; + int result = ES_R_OK; + +#if (GLIB_MAJOR_VERSION <= 2 && GLIB_MINOR_VERSION < 36) + g_type_init(); +#endif + + esd_sent_table = g_hash_table_new(g_str_hash, g_str_equal); + + _D("vconf callbacks size(%d)", vconfcbs_size); + for (i = 0; i < vconfcbs_size; i++) { + ret = vconf_notify_key_changed(vconf_callbacks[i].key, + vconf_callbacks[i].esd_vconfcb_fn, NULL); + if (ret != VCONF_OK) { + _E("failed to register vconf callback (%s)", vconf_callbacks[i].key); + result = ES_R_ERROR; + break; + } + } + + return result; +} + -- 2.7.4 From ec6c5cb6db3b8089c4f7ae678d11365808781a42 Mon Sep 17 00:00:00 2001 From: Jiwoong Im Date: Mon, 23 Nov 2015 16:31:53 +0900 Subject: [PATCH 02/16] move esd to user session. Change-Id: I244238196b87c1d2b8b7920838913207f6cab37c Signed-off-by: Jiwoong Im --- packaging/esd.spec | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packaging/esd.spec b/packaging/esd.spec index b942935..2d2300f 100644 --- a/packaging/esd.spec +++ b/packaging/esd.spec @@ -49,9 +49,9 @@ make %{?jobs:-j%jobs} rm -rf %{buildroot} %make_install -mkdir -p %{buildroot}%{_unitdir}/default.target.wants -install -m 0644 %SOURCE1 %{buildroot}%{_unitdir}/esd.service -ln -sf ../esd.service %{buildroot}%{_unitdir}/default.target.wants/esd.service +mkdir -p %{buildroot}%{_unitdir_user}/default.target.wants +install -m 0644 %SOURCE1 %{buildroot}%{_unitdir_user}/esd.service +ln -sf ../esd.service %{buildroot}%{_unitdir_user}/default.target.wants/esd.service mkdir -p %{buildroot}/usr/share/license cp LICENSE %{buildroot}/usr/share/license/%{name} @@ -64,8 +64,8 @@ cp LICENSE %{buildroot}/usr/share/license/%{name} %config %{_sysconfdir}/dbus-1/system.d/eventsystem.conf %defattr(-,root,root,-) %{_bindir}/esd -%{_unitdir}/esd.service -%{_unitdir}/default.target.wants/esd.service +%{_unitdir_user}/esd.service +%{_unitdir_user}/default.target.wants/esd.service /usr/share/license/%{name} %files devel -- 2.7.4 From bedab2c45f0dd1a036411da471da50e481a9bc77 Mon Sep 17 00:00:00 2001 From: jongmyeongko Date: Fri, 27 Nov 2015 00:46:58 +0900 Subject: [PATCH 03/16] esd 3.0 migration (multi-user feature, dbus-policy) Temporarily, I will keep esd as root-daemon and check full behaviors. Change-Id: I674091b45187be46872bd74a1f4591ec2c166b06 Signed-off-by: jongmyeongko --- CMakeLists.txt | 2 +- eventsystem.conf | 2 + packaging/esd.spec | 15 +- src/esd_main.c | 856 ++++++++++++++++++++++++++++++++--------------------- 4 files changed, 529 insertions(+), 346 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 06a859c..0208eef 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,7 +18,7 @@ INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/src) ### Required packages INCLUDE(FindPkgConfig) -pkg_check_modules(pkgs REQUIRED dlog bundle pkgmgr-info glib-2.0 gio-2.0 appsvc aul ecore vconf) +pkg_check_modules(pkgs REQUIRED dlog bundle pkgmgr-info glib-2.0 gio-2.0 appsvc aul ecore vconf libtzplatform-config libsystemd-daemon cynara-client cynara-creds-gdbus cynara-session) FOREACH(flag ${pkgs_CFLAGS}) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") diff --git a/eventsystem.conf b/eventsystem.conf index 994653b..2773b2f 100644 --- a/eventsystem.conf +++ b/eventsystem.conf @@ -4,6 +4,8 @@ + + diff --git a/packaging/esd.spec b/packaging/esd.spec index 2d2300f..a84789f 100644 --- a/packaging/esd.spec +++ b/packaging/esd.spec @@ -18,6 +18,11 @@ BuildRequires: pkgconfig(glib-2.0) BuildRequires: pkgconfig(pkgmgr) BuildRequires: pkgconfig(eventsystem) BuildRequires: pkgconfig(vconf) +BuildRequires: pkgconfig(libtzplatform-config) +BuildRequires: pkgconfig(libsystemd-daemon) +BuildRequires: pkgconfig(cynara-client) +BuildRequires: pkgconfig(cynara-creds-gdbus) +BuildRequires: pkgconfig(cynara-session) Requires(post): /sbin/ldconfig Requires(postun): /sbin/ldconfig @@ -49,9 +54,9 @@ make %{?jobs:-j%jobs} rm -rf %{buildroot} %make_install -mkdir -p %{buildroot}%{_unitdir_user}/default.target.wants -install -m 0644 %SOURCE1 %{buildroot}%{_unitdir_user}/esd.service -ln -sf ../esd.service %{buildroot}%{_unitdir_user}/default.target.wants/esd.service +mkdir -p %{buildroot}%{_unitdir}/default.target.wants +install -m 0644 %SOURCE1 %{buildroot}%{_unitdir}/esd.service +ln -sf ../esd.service %{buildroot}%{_unitdir}/default.target.wants/esd.service mkdir -p %{buildroot}/usr/share/license cp LICENSE %{buildroot}/usr/share/license/%{name} @@ -64,8 +69,8 @@ cp LICENSE %{buildroot}/usr/share/license/%{name} %config %{_sysconfdir}/dbus-1/system.d/eventsystem.conf %defattr(-,root,root,-) %{_bindir}/esd -%{_unitdir_user}/esd.service -%{_unitdir_user}/default.target.wants/esd.service +%{_unitdir}/esd.service +%{_unitdir}/default.target.wants/esd.service /usr/share/license/%{name} %files devel diff --git a/src/esd_main.c b/src/esd_main.c index 5486111..2093cf5 100644 --- a/src/esd_main.c +++ b/src/esd_main.c @@ -14,11 +14,17 @@ #include #include #include +#include +#include +#include +#include +#include #include "eventsystem_daemon.h" -static GHashTable *event_launch_table; /* table of events for launch_on_event*/ +#define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER) +#define ROOT_USER 0 -static const char *allowed_event_list[] = { }; +static GHashTable *event_launch_table; /* table of events for launch_on_event*/ static const char *event_launch_support_list[] = { SYS_EVENT_BATTERY_CHARGER_STATUS, @@ -33,11 +39,16 @@ struct privilege_info { }; static const struct privilege_info privilege_check_list[] = { - {SYS_EVENT_DISPLAY_STATE, "org.tizen.privilege.display"}, - {SYS_EVENT_WIFI_STATE, "org.tizen.privilege.network.get"}, - {SYS_EVENT_INCOMMING_MSG, "org.tizen.privilege.message.read"} + {SYS_EVENT_DISPLAY_STATE, "http://tizen.org/privilege/display"}, + {SYS_EVENT_WIFI_STATE, "http://tizen.org/privilege/network.get"}, + {SYS_EVENT_INCOMMING_MSG, "http://tizen.org/privilege/message.read"} }; +typedef struct __esd_privilege_check { + char *privilege_name; + int validation; +} esd_privilege_check; + static int privilege_check_size = sizeof(privilege_check_list)/sizeof(struct privilege_info); #ifdef APPFW_EVENT_SYSTEM_EARLIER_FEATURE @@ -63,6 +74,7 @@ static bool g_is_bootcompleted = false; static GHashTable *trusted_busname_table; /* table of dbus bus-names for trusted user-event */ typedef struct __trusted_busname_item { + uid_t uid; char *app_id; char *bus_name; int pid; @@ -73,11 +85,13 @@ typedef struct __eventlaunch_item_param { } eventlaunch_item_param_s; typedef struct esd_list_item { + uid_t uid; char *pkg_id; char *app_id; } esd_list_item_s; typedef struct __event_launch_table_item { + uid_t uid; char *event_name; char *package_name; /* just for passing pointer to app-list removal func */ GList *app_list_evtlaunch; /* app-list for on-event-launch */ @@ -107,67 +121,38 @@ typedef struct esd_info { } esd_info_s; static esd_info_s s_info; +static Ecore_Fd_Handler *g_fd_handler; +sd_login_monitor *g_sd_monitor; + +typedef struct __esd_appctrl_cb_data { + char *appid; + char *pkgid; + uid_t uid; +} esd_appctrl_cb_data; static void __esd_event_handler(char *event_name, bundle *data, void *user_data); static int __esd_add_appinfo_handler(const pkgmgrinfo_appinfo_h handle, void *data); -/* TODO(jongmyeong.ko) */ -/* -static int __esd_get_visibility_from_cert_svc(const char *pkgid, int *visibility) -{ - int ret = ES_R_OK; - const char *cert_value = NULL; - pkgmgrinfo_certinfo_h certinfo = NULL; - - ret = pkgmgrinfo_pkginfo_create_certinfo(&certinfo); - if (ret != PMINFO_R_OK) { - _E("pkgmgrinfo_pkginfo_create_certinfo() failed."); - return ES_R_ERROR; - } - - ret = pkgmgrinfo_pkginfo_load_certinfo(pkgid, certinfo); - if (ret != PMINFO_R_OK) { - _E("pkgmgrinfo_pkginfo_load_certinfo() failed."); - ret = ES_R_ERROR; - goto end; - } +static cynara *r_cynara = NULL; - ret = pkgmgrinfo_pkginfo_get_cert_value(certinfo, PMINFO_DISTRIBUTOR_ROOT_CERT, - &cert_value); - if (ret != PMINFO_R_OK) { - _E("pkgmgrinfo_pkginfo_get_cert_value() failed."); - ret = ES_R_ERROR; - goto end; - } +static int __esd_init_cynara(void) +{ + int ret; - ret = cert_svc_get_visibility_by_root_certificate(cert_value, - strlen(cert_value), visibility); - if (ret != CERT_SVC_ERR_NO_ERROR) { - _E("cert_svc_get_visibility_by_root_cert() failed. err = [%d]", ret); - ret = ES_R_ERROR; - goto end; + ret = cynara_initialize(&r_cynara, NULL); + if (ret != CYNARA_API_SUCCESS) { + _E("cynara initialize failed."); + return ret; } - _D("visibility = [%d]", *visibility); - -end: - pkgmgrinfo_pkginfo_destroy_certinfo(certinfo); - return ret; + return 0; } -*/ -static int __esd_is_sending_allowed_event(const char *event_name) +static void __esd_finish_cynara(void) { - int i = 0; - int size = sizeof(allowed_event_list)/sizeof(*allowed_event_list); - - for (i = 0; i < size; i++) { - if (strcmp(allowed_event_list[i], event_name) == 0) { - return true; - } - } - - return false; + if (r_cynara) + cynara_finish(r_cynara); + r_cynara = NULL; } #ifdef APPFW_EVENT_SYSTEM_EARLIER_FEATURE @@ -200,7 +185,7 @@ static int __esd_check_event_launch_support(const char *event_name) return false; } -static int __get_sender_unixinfo(GDBusConnection *conn, const char *sender_name, const char *type) +static uid_t __get_sender_unixinfo(GDBusConnection *conn, const char *sender_name, const char *type) { GDBusMessage *msg = NULL; GDBusMessage *reply = NULL; @@ -236,7 +221,7 @@ out: if (reply) g_object_unref(reply); - return value; + return (uid_t)value; } static int __get_sender_pid(GDBusConnection *conn, const char *sender_name) @@ -254,9 +239,9 @@ static int __get_sender_pid(GDBusConnection *conn, const char *sender_name) return pid; } -static int __get_sender_uid(GDBusConnection *conn, const char *sender_name) +static uid_t __get_sender_uid(GDBusConnection *conn, const char *sender_name) { - int uid = -1; + uid_t uid = -1; uid = __get_sender_unixinfo(conn, sender_name, "GetConnectionUnixUser"); if (uid < 0) { @@ -268,14 +253,19 @@ static int __get_sender_uid(GDBusConnection *conn, const char *sender_name) return uid; } -static int __esd_check_certificate_match(const char *app_id, const char *from_appid) +static int __esd_check_certificate_match(uid_t uid, const char *app_id, uid_t from_uid, const char *from_appid) { pkgmgrinfo_cert_compare_result_type_e res; int ret = 0; - _D("app_id(%s), from_appid(%s)", app_id, from_appid); + _D("uid(%d), app_id(%s), from_uid(%d), from_appid(%s)", uid, app_id, from_appid); + + if (uid != from_uid) { + /* TODO(jongmyeong.ko): check cert result if uids are not same */ + _D("not same uid"); + } - ret = pkgmgrinfo_pkginfo_compare_usr_app_cert_info(app_id, from_appid, getuid(), &res); + ret = pkgmgrinfo_pkginfo_compare_usr_app_cert_info(app_id, from_appid, uid, &res); if (ret < 0) { _E("failed to check certificate"); return ES_R_ERROR; @@ -289,19 +279,22 @@ static int __esd_check_certificate_match(const char *app_id, const char *from_ap return ES_R_OK; } -static bool __esd_check_application_validation(const char *appid) +static bool __esd_check_application_validation(uid_t uid, const char *appid) { int ret = 0; pkgmgrinfo_appinfo_h handle; - ret = pkgmgrinfo_appinfo_get_usr_appinfo(appid, getuid(), &handle); + ret = pkgmgrinfo_appinfo_get_usr_appinfo(appid, uid, &handle); if (ret != PMINFO_R_OK) return false; pkgmgrinfo_appinfo_destroy_appinfo(handle); + /* FIXME(jongmyeong.ko) */ + /* if (!aul_app_is_running(appid)) return false; + */ return true; } @@ -316,12 +309,12 @@ static void __esd_trusted_busname_print_items(void) while (g_hash_table_iter_next(&iter, &key, &value)) { trusted_item *item = (trusted_item *)value; if (item) { - _D("appid(%s), pid(%d), busname(%s)", item->app_id, item->pid, item->bus_name); + _D("uid(%d), appid(%s), pid(%d), busname(%s)", item->uid, item->app_id, item->pid, item->bus_name); } } } -static int __esd_trusted_busname_add_item(const char *appid, const char *busname, int pid) +static int __esd_trusted_busname_add_item(uid_t uid, const char *appid, const char *busname, int pid) { char *app_id = NULL; char *bus_name = NULL; @@ -342,7 +335,8 @@ static int __esd_trusted_busname_add_item(const char *appid, const char *busname item = (trusted_item *)g_hash_table_lookup(trusted_busname_table, app_id); - if (item && item->bus_name && strcmp(item->bus_name, bus_name) == 0) { + if (item && item->bus_name && strcmp(item->bus_name, bus_name) == 0 && + (item->uid == uid)) { _D("already exist (%s, %s)", app_id, bus_name); FREE_AND_NULL(app_id); FREE_AND_NULL(bus_name); @@ -354,6 +348,7 @@ static int __esd_trusted_busname_add_item(const char *appid, const char *busname FREE_AND_NULL(bus_name); return ES_R_ENOMEM; } + new_item->uid = uid; new_item->app_id = app_id; new_item->bus_name = bus_name; new_item->pid = pid; @@ -370,9 +365,9 @@ static int __esd_check_trusted_events(GDBusConnection *conn, const char *list_na GError *error = NULL; GVariantIter *iter; gchar *str; - char *ptr; char tmp_appid[128] = {0, }; int pid = 0; + uid_t uid = 0; int ret = 0; result = g_dbus_connection_call_sync(conn, @@ -388,27 +383,34 @@ static int __esd_check_trusted_events(GDBusConnection *conn, const char *list_na g_variant_get(result, "(as)", &iter); while (g_variant_iter_loop(iter, "s", &str)) { - if (!(ptr = strstr((const char *)str, "event.busname_session"))) + if (!strstr((const char *)str, "event.busname.session")) continue; _D("list(%s), name(%s)", list_name, str); pid = __get_sender_pid(conn, (const char *)str); if (pid <= 0) { - _E("failed to get pid"); + _E("failed to get pid(%d)", pid); + continue; + } + + uid = __get_sender_uid(conn, (const char *)str); + if (uid < 0) { + _E("failed to get uid(%d)", uid); continue; } + _D("uid(%d)", uid); memset(tmp_appid, 0, sizeof(tmp_appid)); - ret = aul_app_get_appid_bypid(pid, tmp_appid, sizeof(tmp_appid)); + ret = aul_app_get_appid_bypid_for_uid(pid, tmp_appid, sizeof(tmp_appid), uid); if (ret != AUL_R_OK) { _E("failed to get appid by pid(%d)", pid); continue; } _D("appid(%s)", tmp_appid); - if (__esd_check_application_validation(tmp_appid)) { + if (__esd_check_application_validation(uid, tmp_appid)) { _D("add to table"); - ret = __esd_trusted_busname_add_item(tmp_appid, (const char *)str, pid); + ret = __esd_trusted_busname_add_item(uid, tmp_appid, (const char *)str, pid); if (ret < 0) { _E("failed to add item"); } @@ -437,63 +439,61 @@ static int __esd_check_privilege_name(const char *event_name, char **privilege_n return ES_R_OK; } -static bool __esd_check_valid_privilege(const char *appid, const char *privilege_name) +static bool __esd_check_valid_privilege_by_cynara(const char *appid, const char *client, + const char *session, const char *user, const char *privilege_name) { int ret = 0; - int result = 0; bool has_privilege = false; - char *pkg_id = NULL; - pkgmgrinfo_appinfo_h handle; - _D("check privilege, (%s,%s)", appid, privilege_name); - - ret = pkgmgrinfo_appinfo_get_usr_appinfo(appid, getuid(), &handle); - if (ret != PMINFO_R_OK) - return false; + _D("check privilege, (%s, %s, %s, %s, %s)", appid, client, session, user, privilege_name); - ret = pkgmgrinfo_appinfo_get_pkgname(handle, &pkg_id); - if (ret != PMINFO_R_OK) { - pkgmgrinfo_appinfo_destroy_appinfo(handle); - return false; + ret = cynara_check(r_cynara, client, session, user, privilege_name); + if (ret == CYNARA_API_ACCESS_ALLOWED) { + _D("valid privilege"); + has_privilege = true; + } else if (ret == CYNARA_API_ACCESS_DENIED) { + _E("invalid privilege"); + } else { + _E("failed to check privilege, error(%d)", ret); } - /* - * ret = security_server_app_has_privilege(pkg_id, APP_TYPE_EFL, - * privilege_name, &result); - * TODO(jongmyeong.ko) : replace security_server api to cynara api. - */ + return has_privilege; +} - result = 1; - if (ret < 0) { - _E("failed to check privilege, error(%d)", ret); +static int __esd_privilege_func(const char *name, void *user_data) +{ + esd_privilege_check *epc = (esd_privilege_check *)user_data; + + if (strcmp(name, epc->privilege_name) == 0) { + epc->validation = 1; + return -1; } else { - if (result == 1) { - _D("Valid privilege"); - has_privilege = true; - } else { - _E("Invalid privilege"); - } + epc->validation = 0; + return 0; } - - pkgmgrinfo_appinfo_destroy_appinfo(handle); - - return has_privilege; } -static int __esd_check_app_privileged_event(const char *appid, const char *event_name) +static int __esd_check_app_privileged_event(uid_t uid, const char *appid, const char *pkgid, const char *event_name) { char *privilege_name = NULL; - int retval = 0; + char client[256] = {0, }; + char *session = NULL; + char *user = NULL; + int retval = 1; - _D("appid(%s), event_name(%s)", appid, event_name); + _D("event_name(%s), uid(%d), appid(%s), pkgid(%s)", event_name, uid, appid, pkgid); __esd_check_privilege_name(event_name, &privilege_name); - if (privilege_name && !__esd_check_valid_privilege(appid, privilege_name)) { - _E("app(%s) has NOT privilege(%s)", appid, privilege_name); - retval = 0; - } else { - retval = 1; + if (privilege_name) { + /* TODO(jongmyeong.ko): getting client should be replaced by cynara api */ + snprintf(client, 256, "User::App::%s", pkgid); + session = ""; + user = (char *)g_strdup_printf("%u", uid); + if (!__esd_check_valid_privilege_by_cynara(appid, client, "", user, privilege_name)) { + _E("app(%s) has NOT privilege(%s)", appid, privilege_name); + retval = 0; + } } return retval; @@ -504,7 +504,7 @@ static void __esd_print_appid_with_eventid(gpointer data, gpointer user_data) esd_list_item_s *item = (esd_list_item_s *)data; char *event_name = (char *)user_data; - _D("event_name(%s)-app_id(%s)-pkg_id(%s)", event_name, item->app_id, item->pkg_id); + _D("event_name(%s)-uid(%d)-app_id(%s)-pkg_id(%s)", event_name, item->uid, item->app_id, item->pkg_id); } static void __esd_print_interested_event(gpointer data, gpointer user_data) @@ -532,83 +532,31 @@ static int __esd_find_compare_by_list_item(gconstpointer data, gconstpointer use esd_list_item_s *item_1 = (esd_list_item_s *)user_data; esd_list_item_s *item_2 = (esd_list_item_s *)data; - return strcmp(item_1->app_id, item_2->app_id) | + return (item_1->uid != item_2->uid) | + strcmp(item_1->app_id, item_2->app_id) | strcmp(item_1->pkg_id, item_2->pkg_id); } -static int __esd_get_pkgid_by_appid(const char *app_id, char **pkg_id) -{ - pkgmgrinfo_appinfo_h handle = NULL; - char *temp_val = NULL; - int ret = 0; - int result = ES_R_OK; - - *pkg_id = NULL; - - ret = pkgmgrinfo_appinfo_get_usr_appinfo(app_id, getuid(), &handle); - if (ret < 0) { - _E("failed to get appinfo"); - result = ES_R_ERROR; - goto out; - } - - ret = pkgmgrinfo_appinfo_get_pkgname(handle, &temp_val); - if (ret == PMINFO_R_OK && temp_val) { - *pkg_id = strdup(temp_val); - if (*pkg_id == NULL) { - _E("out of memory"); - result = ES_R_ENOMEM; - } - _D("pkg_id(%s)", *pkg_id); - } else { - _E("failed to get pkgname"); - result = ES_R_ERROR; - } - -out: - if (handle) { - ret = pkgmgrinfo_appinfo_destroy_appinfo(handle); - if (ret != PMINFO_R_OK) { - _E("failed to destroy appinfo"); - result = ES_R_ERROR; - } - } - - if (result != ES_R_OK) - FREE_AND_NULL(*pkg_id); - - return result; -} - -static int __esd_add_list_item(event_launch_item *el_item, +static int __esd_add_list_item(uid_t uid, event_launch_item *el_item, const char *app_id, const char *pkg_id) { - char *_pkgid = NULL; esd_list_item_s *item_of_list = NULL; - if (pkg_id == NULL) { - if (__esd_get_pkgid_by_appid(app_id, &_pkgid) < 0) { - return ES_R_ERROR; - } - } else { - _pkgid = (char *)pkg_id; - } - item_of_list = calloc(1, sizeof(esd_list_item_s)); if (item_of_list == NULL) { _E("out_of_memory"); - free(_pkgid); return ES_R_ENOMEM; } + item_of_list->uid = uid; item_of_list->app_id = (char *)app_id; - item_of_list->pkg_id = _pkgid; + item_of_list->pkg_id = (char *)pkg_id; el_item->app_list_evtlaunch = g_list_append(el_item->app_list_evtlaunch, item_of_list); return ES_R_OK; } -static int __esd_add_launch_item(const char *event_name, const char *appid) +static int __esd_add_launch_item(uid_t uid, const char *event_name, const char *appid, const char *pkgid) { GList *app_list = NULL; guint subscription_id = 0; @@ -620,17 +568,14 @@ static int __esd_add_launch_item(const char *event_name, const char *appid) (event_launch_item *)g_hash_table_lookup(event_launch_table, event_name); if (el_item) { - if (__esd_get_pkgid_by_appid(appid, &pkg_id) < 0) { - return ES_R_ERROR; - } item_of_list = calloc(1, sizeof(esd_list_item_s)); if (item_of_list == NULL) { _E("memory alloc failed"); - free(pkg_id); return ES_R_ENOMEM; } + item_of_list->uid = uid; item_of_list->app_id = (char *)appid; - item_of_list->pkg_id = pkg_id; + item_of_list->pkg_id = (char *)pkgid; app_list = g_list_find_custom(el_item->app_list_evtlaunch, item_of_list, (GCompareFunc)__esd_find_compare_by_list_item); @@ -640,13 +585,18 @@ static int __esd_add_launch_item(const char *event_name, const char *appid) app_id = strdup((char *)appid); if (!app_id) { _E("out_of_memory"); - free(pkg_id); return ES_R_ENOMEM; } - if (__esd_add_list_item(el_item, app_id, pkg_id) < 0) { + pkg_id = strdup((char *)pkgid); + if (!pkg_id) { + _E("out_of_memory"); + FREE_AND_NULL(app_id); + return ES_R_ENOMEM; + } + if (__esd_add_list_item(uid, el_item, app_id, pkg_id) < 0) { _E("failed to add list item"); - free(app_id); - free(pkg_id); + FREE_AND_NULL(app_id); + FREE_AND_NULL(pkg_id); return ES_R_ERROR; } } @@ -672,9 +622,20 @@ static int __esd_add_launch_item(const char *event_name, const char *appid) FREE_AND_NULL(eli); return ES_R_ENOMEM; } - if (__esd_add_list_item(eli, app_id, NULL) < 0) { + + pkg_id = strdup((char *)pkgid); + if (!pkg_id) { + _E("out_of_memory"); + FREE_AND_NULL(app_id); + FREE_AND_NULL(eli->event_name); + FREE_AND_NULL(eli); + return ES_R_ENOMEM; + } + + if (__esd_add_list_item(uid, eli, app_id, pkg_id) < 0) { _E("failed to add list item"); - free(app_id); + FREE_AND_NULL(app_id); + FREE_AND_NULL(pkg_id); FREE_AND_NULL(eli->event_name); FREE_AND_NULL(eli); return ES_R_ERROR; @@ -696,23 +657,65 @@ static int __esd_add_launch_item(const char *event_name, const char *appid) return ES_R_OK; } +static void __esd_remove_all_private_usr_app_list(gpointer data, gpointer user_data) +{ + esd_list_item_s *item = (esd_list_item_s *)data; + event_launch_item *eli = (event_launch_item *)user_data; + + if (item->uid != GLOBAL_USER && !strcmp(eli->package_name, item->pkg_id)) { + _D("uid(%d), app_id(%s), pkg_id(%s)", item->uid, item->app_id, eli->package_name); + eli->app_list_evtlaunch = g_list_remove_all(eli->app_list_evtlaunch, data); + } +} + +static int __esd_launch_table_remove_private_usr_items(void) +{ + GHashTableIter iter; + gpointer key, value; + event_launch_item *eli = NULL; + GList *first_list = NULL; + + g_hash_table_iter_init(&iter, event_launch_table); + + while (g_hash_table_iter_next(&iter, &key, &value)) { + eli = (event_launch_item *)value; + g_list_foreach(eli->app_list_evtlaunch, __esd_remove_all_private_usr_app_list, eli); + + first_list = g_list_first(eli->app_list_evtlaunch); + if (first_list == NULL) { + if (eli->reg_id) { + eventsystem_unregister_event(eli->reg_id); + } + g_hash_table_iter_remove(&iter); + } + } + + return ES_R_OK; +} + static void __esd_remove_app_list(gpointer data, gpointer user_data) { + bool skip = false; esd_list_item_s *item = (esd_list_item_s *)data; event_launch_item *eli = (event_launch_item *)user_data; - if (!strcmp(eli->package_name, item->pkg_id)) { + if (eli->uid != GLOBAL_USER && eli->uid != item->uid) { + skip = true; + } + + if (!skip && !strcmp(eli->package_name, item->pkg_id)) { _D("pkg_id(%s), app_id(%s)", eli->package_name, item->app_id); eli->app_list_evtlaunch = g_list_remove_all(eli->app_list_evtlaunch, data); } } -static int __esd_remove_launch_item(gpointer data, const char *pkg_id) +static int __esd_remove_launch_item(uid_t uid, gpointer data, const char *pkg_id) { event_launch_item *eli = (event_launch_item *)data; GList *first_list = NULL; + eli->uid = uid; eli->package_name = (char *)pkg_id; g_list_foreach(eli->app_list_evtlaunch, __esd_remove_app_list, eli); @@ -727,7 +730,7 @@ static int __esd_remove_launch_item(gpointer data, const char *pkg_id) return ES_R_OK; } -static int __esd_launch_table_remove_items(const char *pkg_id) +static int __esd_launch_table_remove_items(uid_t uid, const char *pkg_id) { GHashTableIter iter; gpointer key, value; @@ -735,7 +738,7 @@ static int __esd_launch_table_remove_items(const char *pkg_id) g_hash_table_iter_init(&iter, event_launch_table); while (g_hash_table_iter_next(&iter, &key, &value)) { - if (__esd_remove_launch_item(value, pkg_id) == ES_R_REMOVE) { + if (__esd_remove_launch_item(uid, value, pkg_id) == ES_R_REMOVE) { _D("remove item itself"); g_hash_table_iter_remove(&iter); } @@ -747,6 +750,8 @@ static int __esd_launch_table_remove_items(const char *pkg_id) static void __esd_event_launch_with_appid(gpointer data, gpointer user_data) { esd_list_item_s *item = (esd_list_item_s *)data; + uid_t uid = item->uid; + uid_t from_uid = 0; char *app_id = item->app_id; esd_event_param *eep = (esd_event_param *)user_data; char *from_appid = (char *)eep->user_data; @@ -756,15 +761,22 @@ static void __esd_event_launch_with_appid(gpointer data, gpointer user_data) _D("launch_on_event: app_id(%s), event_name(%s)", app_id, eep->event_name); + /* TODO(jongmyeong.ko): for launch by user-event */ + /* if (from_appid && from_appid[0] != '\0') { - ret = __esd_check_certificate_match(app_id, from_appid); + ret = __esd_check_certificate_match(uid, app_id, from_uid, from_appid); if (ret != ES_R_OK) { _D("from_appid(%s), no same cert", from_appid); return; } } + */ + /* FIXME(jongmyeong.ko): aul_app_is_running */ + /* if (!aul_app_is_running(app_id)) { + */ + if (1) { char event_uri[1024] = {0, }; snprintf(event_uri, 1024, "event://%s", eep->event_name); bundle *b = bundle_dup(eep->event_data); @@ -772,8 +784,8 @@ static void __esd_event_launch_with_appid(gpointer data, gpointer user_data) appsvc_set_uri(b, event_uri); appsvc_set_appid(b, app_id); - pid = appsvc_usr_run_service(b, req_id++, NULL, eep->user_data, getuid()); - _D("pid(%d)", pid); + pid = appsvc_usr_run_service(b, req_id++, NULL, eep->user_data, uid); + _D("uid(%d), pid(%d)", uid, pid); bundle_free(b); } else { @@ -931,6 +943,167 @@ static void __esd_event_handler(char *event_name, bundle *data, void *user_data) } } +static void __esd_trusted_busname_remove_item(char *bus_name) +{ + GHashTableIter iter; + gpointer key, value; + + g_hash_table_iter_init(&iter, trusted_busname_table); + + while (g_hash_table_iter_next(&iter, &key, &value)) { + trusted_item *item = (trusted_item *)value; + if (item) { + if (strcmp(bus_name, item->bus_name) == 0) { + _D("remove trusted busname item(%s, %s)", item->app_id, item->bus_name); + FREE_AND_NULL(item->app_id); + FREE_AND_NULL(item->bus_name); + FREE_AND_NULL(item); + g_hash_table_iter_remove(&iter); + + __esd_trusted_busname_print_items(); + } + } + } +} + +static void __esd_filter_name_owner_changed(GDBusConnection *connection, + const gchar *sender_name, const gchar *object_path, + const gchar *interface_name, const gchar *signal_name, + GVariant *parameters, gpointer user_data) +{ + char *name = NULL; + char *old_owner = NULL; + char *new_owner = NULL; + int old_len = 0; + int new_len = 0; + + g_variant_get(parameters, "(sss)", &name, &old_owner, &new_owner); + + if (strstr(name, "event.busname.session")) { + old_len = strlen(old_owner); + new_len = strlen(new_owner); + + _D("changed name(%s), old_onwer(%s)(%d) -> new_onwer(%s)(%d)", + name, old_owner, old_len, new_owner, new_len); + + if (old_len > 0 && new_len == 0) { + __esd_trusted_busname_remove_item(name); + } else if (old_len == 0 && new_len > 0) { + _D("new name owned"); + } else { + _E("not-expected name change"); + } + } +} + +static int __esd_dbus_name_monitor(GDBusConnection *connection) +{ + guint name_owner_changed_id = 0; + + name_owner_changed_id = g_dbus_connection_signal_subscribe(connection, + "org.freedesktop.DBus", "org.freedesktop.DBus", + "NameOwnerChanged", "/org/freedesktop/DBus", NULL, G_DBUS_SIGNAL_FLAGS_NONE, + __esd_filter_name_owner_changed, NULL, NULL); + + _I("name_owner_changed_id(%d)", name_owner_changed_id); + + return ES_R_OK; +} + +static int __esd_get_user_items(void) +{ + int ret = 0; + int i = 0; + uid_t *uids = NULL; + uid_t cur_uid = 0; + + ret = sd_get_uids(&uids); + if (ret < 0) { + _E("failed to get uids (%d)", ret); + return ES_R_ERROR; + } + + if (ret == 0 || uids == NULL) { + _I("there is no uid for now"); + } else { + /* reset user's item */ + __esd_launch_table_remove_private_usr_items(); + for (i = 0; i < ret; i++) { + cur_uid = uids[i]; + _I("found uid(%d)", cur_uid); + + ret = pkgmgrinfo_appinfo_get_usr_installed_list(__esd_add_appinfo_handler, cur_uid, &cur_uid); + if (ret < 0) { + _E("failed to get user(%d)-app list (%d)", cur_uid, ret); + } + } + } + + __esd_launch_table_print_items(); + + return ES_R_OK; +} + +static Eina_Bool __esd_fd_handler_func(void *data, Ecore_Fd_Handler *fd_handler) +{ + if (ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_READ)) { + _I("fd read"); + __esd_get_user_items(); + } + + return ECORE_CALLBACK_CANCEL; +} + +static int __esd_start_sd_monitor(void) +{ + int ret = 0; + int fd = 0; + + ret = __esd_get_user_items(); + if (ret < 0) { + return ES_R_ERROR; + } + + ret = sd_login_monitor_new("uid", &g_sd_monitor); + if (ret < 0) { + _E("sd_login_monitor_new error (%d)", ret); + return ES_R_ERROR; + } + + fd = sd_login_monitor_get_fd(g_sd_monitor); + if (fd < 0) { + _E("sd_login_monitor_get_fd error"); + sd_login_monitor_unref(g_sd_monitor); + return ES_R_ERROR; + } + + g_fd_handler = ecore_main_fd_handler_add(fd, + (Ecore_Fd_Handler_Flags)(ECORE_FD_READ | ECORE_FD_ERROR), + __esd_fd_handler_func, NULL, NULL, NULL); + if (g_fd_handler == NULL) { + _E("fd_handler is NULL"); + sd_login_monitor_unref(g_sd_monitor); + return ES_R_ERROR; + } + + _I("setup sd-monitor done"); + + return ES_R_OK; +} + +static int __esd_stop_sd_monitor(void) +{ + _I("stop sd_monitor"); + if (g_fd_handler) { + ecore_main_fd_handler_del(g_fd_handler); + g_fd_handler = NULL; + } + + sd_login_monitor_unref(g_sd_monitor); + g_sd_monitor = 0; + + return ES_R_OK; +} static GDBusNodeInfo *introspection_data; static const gchar introspection_xml[] = @@ -989,21 +1162,24 @@ static const gchar introspection_xml[] = " " ""; -static int __esd_get_appid_by_pid(int pid, char *app_id, int buf_size) +static int __esd_get_appid_by_pid(int pid, uid_t uid, char *app_id, int buf_size) { int retval = ES_R_OK; int ret = 0; - if (pid > 0) { - ret = aul_app_get_appid_bypid(pid, app_id, buf_size); + if (pid <= 0) { + _E("invalid pid(%d)", pid); + retval = ES_R_ERROR; + } else if (uid <= 0) { + _E("invalid uid(%d)", uid); + retval = ES_R_ERROR; + } else { + ret = aul_app_get_pkgid_bypid_for_uid(pid, app_id, buf_size, (uid_t)uid); if (ret != AUL_R_OK) { _E("failed to get appid by pid"); retval = ES_R_ERROR; } - _D("pid(%d)-appid(%s)", pid, app_id); - } else { - _E("invalid pid"); - retval = ES_R_ERROR; + _D("pid(%d)-uid(%d)-appid(%s)", pid, uid, app_id); } return retval; @@ -1061,19 +1237,21 @@ static int check_user_event_sender_valid(const char *event_name, const char *app return retval; } -static void check_sender_valid_method_call(GVariant *parameters, - GDBusMethodInvocation *invocation) +static void check_sender_valid_method_call(GDBusConnection *connection, const gchar *sender, + GVariant *parameters, GDBusMethodInvocation *invocation) { GVariant *param = NULL; int result = 0; char *event_name = NULL; char app_id[128] = {0, }; - int sender_pid = 0; + int event_sender_pid = 0; + uid_t sender_uid = 0; - g_variant_get(parameters, "(is)", &sender_pid, &event_name); - _D("sender_pid(%d), event_name(%s)", sender_pid, event_name); + g_variant_get(parameters, "(is)", &event_sender_pid, &event_name); + _D("event_sender_pid(%d), event_name(%s)", event_sender_pid, event_name); - if (__esd_get_appid_by_pid(sender_pid, app_id, sizeof(app_id)) < 0) { + sender_uid = __get_sender_uid(connection, sender); + if (__esd_get_appid_by_pid(event_sender_pid, sender_uid, app_id, sizeof(app_id)) < 0) { result = ES_R_ERROR; } else { if (check_user_event_sender_valid(event_name, app_id) < 0) { @@ -1097,12 +1275,14 @@ static void check_send_event_valid_method_call(GDBusConnection *connection, cons char *event_name = NULL; char app_id[128] = {0, }; int sender_pid = 0; + uid_t sender_uid = 0; g_variant_get(parameters, "(s)", &event_name); _D("event_name(%s)", event_name); sender_pid = __get_sender_pid(connection, sender); - if (__esd_get_appid_by_pid(sender_pid, app_id, sizeof(app_id)) < 0) { + sender_uid = __get_sender_uid(connection, sender); + if (__esd_get_appid_by_pid(sender_pid, sender_uid, app_id, sizeof(app_id)) < 0) { result = ES_R_ERROR; } else { if (check_user_event_sender_valid(event_name, app_id) < 0) { @@ -1129,7 +1309,9 @@ static void get_trusted_peer_method_call(GDBusConnection *connection, const gcha char *event_name = NULL; char app_id[128] = {0, }; int sender_pid = 0; + uid_t sender_uid = 0; int ret = 0; + uid_t uid = 0; char *_appid = NULL; char *_busname = NULL; @@ -1137,7 +1319,8 @@ static void get_trusted_peer_method_call(GDBusConnection *connection, const gcha _D("event_name(%s)", event_name); sender_pid = __get_sender_pid(connection, sender); - if (__esd_get_appid_by_pid(sender_pid, app_id, sizeof(app_id)) < 0) { + sender_uid = __get_sender_uid(connection, sender); + if (__esd_get_appid_by_pid(sender_pid, sender_uid, app_id, sizeof(app_id)) < 0) { result = ES_R_ERROR; } else { builder = g_variant_builder_new(G_VARIANT_TYPE("as")); @@ -1145,10 +1328,15 @@ static void get_trusted_peer_method_call(GDBusConnection *connection, const gcha g_hash_table_iter_init(&iter, trusted_busname_table); while (g_hash_table_iter_next(&iter, &key, &value)) { trusted_item *item = (trusted_item *)value; + uid = item->uid; _appid = item->app_id; _busname = item->bus_name; - ret = __esd_check_certificate_match(_appid, app_id); + if (uid != GLOBAL_USER && uid != sender_uid) { + continue; + } + + ret = __esd_check_certificate_match(uid, _appid, sender_uid, app_id); if (ret == ES_R_OK) { g_variant_builder_add(builder, "s", _busname); } @@ -1174,6 +1362,7 @@ static void setup_trusted_peer_method_call(GDBusConnection *connection, const gc char *destination_name = NULL; char app_id[128] = {0, }; int sender_pid = 0; + uid_t sender_uid = 0; int ret = 0; g_variant_get(parameters, "(ss)", &event_name, &destination_name); @@ -1181,10 +1370,11 @@ static void setup_trusted_peer_method_call(GDBusConnection *connection, const gc if (destination_name && destination_name[0] != '\0') { sender_pid = __get_sender_pid(connection, sender); - if (__esd_get_appid_by_pid(sender_pid, app_id, sizeof(app_id)) < 0) { + sender_uid = __get_sender_uid(connection, sender); + if (__esd_get_appid_by_pid(sender_pid, sender_uid, app_id, sizeof(app_id)) < 0) { result = ES_R_ERROR; } else { - ret = __esd_trusted_busname_add_item(app_id, destination_name, + ret = __esd_trusted_busname_add_item(sender_uid, app_id, destination_name, sender_pid); if (ret < 0) { _E("failed to add trusted busname item"); @@ -1212,6 +1402,11 @@ static void check_privilege_valid_method_call(GDBusConnection *connection, const char *privilege_name = NULL; char app_id[128] = {0, }; int sender_pid = 0; + uid_t sender_uid = 0; + char *client = NULL; + char *session = NULL; + char *user = NULL; + int ret = 0; g_variant_get(parameters, "(s)", &event_name); __esd_check_privilege_name(event_name, &privilege_name); @@ -1219,96 +1414,43 @@ static void check_privilege_valid_method_call(GDBusConnection *connection, const if (privilege_name) { sender_pid = __get_sender_pid(connection, sender); - if (__esd_get_appid_by_pid(sender_pid, app_id, sizeof(app_id)) < 0) { + sender_uid = __get_sender_uid(connection, sender); + if (__esd_get_appid_by_pid(sender_pid, sender_uid, app_id, sizeof(app_id)) < 0) { result = ES_R_ERROR; } else { - if (__esd_check_valid_privilege(app_id, privilege_name)) { - result = 1; - } else { + ret = cynara_creds_gdbus_get_client(connection, sender, CLIENT_METHOD_PID, &client); + if (ret != CYNARA_API_SUCCESS) { + _E("failed to get client"); result = ES_R_EINVAL; + goto out; } - } - } else { - result = 1; - } - param = g_variant_new("(i)", result); - _D("event_name(%s), result(%d)", event_name, result); - g_dbus_method_invocation_return_value(invocation, param); -} - -static void request_sending_event_method_call(GDBusConnection *connection, const gchar *sender, - GVariant *parameters, GDBusMethodInvocation *invocation) -{ - GVariant *param = NULL; - int result = 0; - char *event_name = NULL; - bundle_raw *raw = NULL; - bundle *b = NULL; - int len = 0; - const char *access_rule = NULL; - const char *check_object = NULL; - char app_id[128] = {0, }; - char *pkg_id = NULL; - int sender_pid = 0; - int sender_uid = -1; - int visibility = 0; - int send_flag = 0; - int ret = 0; - - g_variant_get(parameters, "(ssi)", &event_name, &raw, &len); - _D("event_name(%s)", event_name); - - if (!__esd_is_sending_allowed_event(event_name)) { - /* no effect */ - _E("not allowed"); - result = 1; - goto end; - } - - sender_uid = __get_sender_uid(connection, sender); - _D("uid(%d), getuid(%d)", sender_uid, getuid()); - if (sender_uid >= 0 && sender_uid <= getuid()) { - send_flag = 1; - goto end; - } + ret = cynara_creds_gdbus_get_user(connection, sender, USER_METHOD_UID, &user); + if (ret != CYNARA_API_SUCCESS) { + _E("failed to get user"); + result = ES_R_EINVAL; + goto out; + } - /* TODO(jongmyeong.ko) */ - /* - sender_pid = __get_sender_pid(connection, sender); - if (sender_pid > 0) { - if (__esd_get_appid_by_pid(sender_pid, app_id, sizeof(app_id)) < 0) { - result = ES_R_ERROR; - } else { - if (__esd_get_pkgid_by_appid(app_id, &pkg_id) < 0) { - result = ES_R_ERROR; + session = cynara_session_from_pid(sender_pid); + if (session == NULL) { + _E("failed to get session"); + result = ES_R_EINVAL; + goto out; } - } - } - if (pkg_id) { - if (__esd_get_visibility_from_cert_svc(pkg_id, &visibility) < 0) { - result = ES_R_ERROR; - } else { - if (visibility == CERT_SVC_VISIBILITY_PLATFORM) { - _D("platfrom package"); - send_flag = 1; + if (__esd_check_valid_privilege_by_cynara(app_id, client, session, user, privilege_name)) { + result = 1; + } else { + result = ES_R_EINVAL; } } - FREE_AND_NULL(pkg_id); - } - */ - -end: - if (send_flag) { - b = bundle_decode(raw, len); - eventsystem_send_system_event(event_name, b); - bundle_free(b); + } else { result = 1; } +out: param = g_variant_new("(i)", result); - _D("event_name(%s), result(%d)", event_name, result); g_dbus_method_invocation_return_value(invocation, param); } @@ -1361,7 +1503,7 @@ static void handle_method_call(GDBusConnection *connection, gpointer user_data) { if (g_strcmp0(method_name, "CheckSenderValidation") == 0) { - check_sender_valid_method_call(parameters, invocation); + check_sender_valid_method_call(connection, sender, parameters, invocation); } else if (g_strcmp0(method_name, "GetTrustedPeerList") == 0) { get_trusted_peer_method_call(connection, sender, parameters, invocation); } else if (g_strcmp0(method_name, "SetupTrustedPeer") == 0) { @@ -1370,8 +1512,6 @@ static void handle_method_call(GDBusConnection *connection, check_privilege_valid_method_call(connection, sender, parameters, invocation); } else if (g_strcmp0(method_name, "CheckUserSendValidation") == 0) { check_send_event_valid_method_call(connection, sender, parameters, invocation); - } else if (g_strcmp0(method_name, "RequestSendingEvent") == 0) { - request_sending_event_method_call(connection, sender, parameters, invocation); #ifdef APPFW_EVENT_SYSTEM_EARLIER_FEATURE } else if (g_strcmp0(method_name, "GetEarlierData") == 0) { get_earlier_data_method_call(parameters, invocation); @@ -1385,10 +1525,10 @@ static const GDBusInterfaceVTable interface_vtable = { NULL }; -static void on_bus_acquired(GDBusConnection *connection, +static void __esd_on_bus_acquired(GDBusConnection *connection, const gchar *name, gpointer user_data) { - _I("on_bus_acquired(%s)", name); + _I("bus acquired(%s)", name); guint reg_id = 0; GError *error = NULL; @@ -1404,10 +1544,10 @@ static void on_bus_acquired(GDBusConnection *connection, } } -static void on_name_acquired(GDBusConnection *connection, +static void __esd_on_name_acquired(GDBusConnection *connection, const gchar *name, gpointer user_data) { - _I("on_name_acquired(%s)", name); + _I("name acquired(%s)", name); __esd_check_trusted_events(connection, "ListNames"); __esd_check_trusted_events(connection, "ListActivatableNames"); @@ -1420,17 +1560,22 @@ static void on_name_acquired(GDBusConnection *connection, __esd_register_vconf_callbacks(); __esd_trusted_busname_print_items(); + + __esd_start_sd_monitor(); + + __esd_dbus_name_monitor(connection); } -static void on_name_lost(GDBusConnection *connection, +static void __esd_on_name_lost(GDBusConnection *connection, const gchar *name, gpointer user_data) { - _E("on_name_lost(%s)", name); + _E("name lost(%s)", name); } static int __esd_before_loop(void) { int ret = 0; + uid_t uid = 0; #ifdef APPFW_EVENT_SYSTEM_EARLIER_FEATURE guint subscription_id = 0; @@ -1557,11 +1702,15 @@ static int __esd_before_loop(void) event_launch_table = g_hash_table_new(g_str_hash, g_str_equal); _I("get event launch list"); - ret = pkgmgrinfo_appinfo_get_usr_installed_list(__esd_add_appinfo_handler, getuid(), NULL); + + /* get global user info */ + uid = GLOBAL_USER; + ret = pkgmgrinfo_appinfo_get_usr_installed_list(__esd_add_appinfo_handler, uid, &uid); if (ret < 0) { - _E("pkgmgrinfo_appinfo_get_usr_installed_list error"); + _E("failed to get global-app list (%d)", ret); return ES_R_ERROR; } + __esd_launch_table_print_items(); trusted_busname_table = g_hash_table_new(g_str_hash, g_str_equal); @@ -1581,9 +1730,9 @@ static int __esd_before_loop(void) owner_id = g_bus_own_name(G_BUS_TYPE_SYSTEM, ESD_BUS_NAME, G_BUS_NAME_OWNER_FLAGS_NONE, - on_bus_acquired, - on_name_acquired, - on_name_lost, + __esd_on_bus_acquired, + __esd_on_name_acquired, + __esd_on_name_lost, NULL, NULL); if (!owner_id) { _E("g_bus_own_name error"); @@ -1608,12 +1757,23 @@ static void __esd_pkgmgr_event_free(esd_pkgmgr_event *pkg_event) static int __esd_appcontrol_cb(const char *operation, const char *uri, const char *mime, void *data) { - char *appid = (char *)data; + esd_appctrl_cb_data *cb_data = (esd_appctrl_cb_data *)data; + char *appid = NULL; + char *pkgid = NULL; char *event_name = NULL; const char *prefix = "event://"; + uid_t uid = 0; + + if (cb_data == NULL) { + _E("invalid data"); + return 0; + } + appid = cb_data->appid; + pkgid = cb_data->pkgid; + uid = cb_data->uid; - _D("appid(%s), operation(%s), uri(%s), mime(%s)", - appid, operation, uri, mime); + _D("uid(%d), appid(%s), pkgid(%s), operation(%s), uri(%s), mime(%s)", + uid, appid, pkgid, operation, uri, mime); if (!strcmp(operation, APPSVC_OPERATION_LAUNCH_ON_EVENT)) { if (!strncmp(uri, prefix, strlen(prefix))) { @@ -1622,10 +1782,10 @@ static int __esd_appcontrol_cb(const char *operation, _D("appid(%s), event_name(%s)", appid, event_name); if (!__esd_check_event_launch_support(event_name)) { _E("failed to add item (not support event)"); - } else if (!__esd_check_app_privileged_event(appid, event_name)) { + } else if (!__esd_check_app_privileged_event(uid, appid, pkgid, event_name)) { _E("failed to add item (no privilege)"); } else { - if (__esd_add_launch_item(event_name, appid)) { + if (__esd_add_launch_item(uid, event_name, appid, pkgid)) { _E("failed to add item"); } } @@ -1644,12 +1804,27 @@ static int __esd_appcontrol_cb(const char *operation, static int __esd_add_appinfo_handler(const pkgmgrinfo_appinfo_h handle, void *data) { char *appid = NULL; + char *pkgid = NULL; pkgmgrinfo_app_component component_type; int ret = 0; + uid_t *p_uid = NULL; + + if (data == NULL) { + _E("invalid data"); + return ES_R_ERROR; + } + + p_uid = (uid_t *)data; ret = pkgmgrinfo_appinfo_get_appid(handle, &appid); if (ret < 0) { - _E("fail to get appinfo"); + _E("failed to get appid"); + return ES_R_ERROR; + } + + ret = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgid); + if (ret < 0) { + _E("failed to get pkgid"); return ES_R_ERROR; } @@ -1659,9 +1834,34 @@ static int __esd_add_appinfo_handler(const pkgmgrinfo_appinfo_h handle, void *da return ES_R_ERROR; } + _D("uid(%d), appid(%s), component_type(%d)", *p_uid, appid, component_type); if (component_type == PMINFO_SVC_APP) { + esd_appctrl_cb_data *cb_data = calloc(1, sizeof(esd_appctrl_cb_data)); + if (cb_data == NULL) { + _E("memory alloc failed"); + return ES_R_ENOMEM; + } + cb_data->appid = strdup(appid); + if (cb_data->appid == NULL) { + _E("out_of_memory"); + FREE_AND_NULL(cb_data); + return ES_R_ENOMEM; + } + cb_data->pkgid = strdup(pkgid); + if (cb_data->pkgid == NULL) { + _E("out_of_memory"); + FREE_AND_NULL(cb_data->appid); + FREE_AND_NULL(cb_data); + return ES_R_ENOMEM; + } + cb_data->uid = *p_uid; ret = pkgmgrinfo_appinfo_foreach_appcontrol(handle, - (pkgmgrinfo_app_control_list_cb)__esd_appcontrol_cb, appid); + (pkgmgrinfo_app_control_list_cb)__esd_appcontrol_cb, cb_data); + + FREE_AND_NULL(cb_data->pkgid); + FREE_AND_NULL(cb_data->appid); + FREE_AND_NULL(cb_data); + if (ret < 0) { _E("failed to get appcontrol info"); return ES_R_ERROR; @@ -1672,7 +1872,7 @@ static int __esd_add_appinfo_handler(const pkgmgrinfo_appinfo_h handle, void *da return ES_R_OK; } -static int __esd_pkgmgr_event_callback(uid_t uid, int req_id, const char *pkg_type, +static int __esd_pkgmgr_event_callback(uid_t target_uid, int req_id, const char *pkg_type, const char *pkgid, const char *key, const char *val, const void *pmsg, void *data) { @@ -1680,8 +1880,8 @@ static int __esd_pkgmgr_event_callback(uid_t uid, int req_id, const char *pkg_ty pkgmgrinfo_pkginfo_h handle = NULL; int ret = 0; - _D("req_id(%d), pkg_type(%s), pkgid(%s), key(%s), val(%s)", - req_id, pkg_type, pkgid, key, val); + _D("target_uid(%d), req_id(%d), pkg_type(%s), pkgid(%s), key(%s), val(%s)", + target_uid, req_id, pkg_type, pkgid, key, val); if (strncmp(key, "start", strlen(key)) == 0) { if (strcmp(val, "install") == 0) { @@ -1700,14 +1900,14 @@ static int __esd_pkgmgr_event_callback(uid_t uid, int req_id, const char *pkg_ty } else if (strcmp(key, "end") == 0 && strcmp(val, "ok") == 0) { if (pkg_event->type == INSTALL || pkg_event->type == UPDATE) { _D("install end (ok)"); - ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, uid, &handle); + ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, target_uid, &handle); if (ret < 0) { _E("failed to get pkginfo"); __esd_pkgmgr_event_free(pkg_event); return 0; } - ret = pkgmgrinfo_appinfo_get_list(handle, - PMINFO_ALL_APP, __esd_add_appinfo_handler, NULL); + ret = pkgmgrinfo_appinfo_get_usr_list(handle, + PMINFO_ALL_APP, __esd_add_appinfo_handler, &target_uid, target_uid); if (ret < 0) { _E("failed to get appinfo"); __esd_pkgmgr_event_free(pkg_event); @@ -1721,7 +1921,7 @@ static int __esd_pkgmgr_event_callback(uid_t uid, int req_id, const char *pkg_ty } } else if (pkg_event->type == UNINSTALL) { _D("uninstall end (ok)"); - __esd_launch_table_remove_items(pkgid); + __esd_launch_table_remove_items(target_uid, pkgid); __esd_launch_table_print_items(); } __esd_pkgmgr_event_free(pkg_event); @@ -1737,34 +1937,6 @@ static int __esd_pkgmgr_event_callback(uid_t uid, int req_id, const char *pkg_ty return 0; } -static int __esd_app_dead_handler(int pid, void *data) -{ - GHashTableIter iter; - gpointer key, value; - - _I("pid: %d", pid); - - if (pid <= 0) - return 0; - - g_hash_table_iter_init(&iter, trusted_busname_table); - - while (g_hash_table_iter_next(&iter, &key, &value)) { - trusted_item *item = (trusted_item *)value; - if (item) { - if (pid == item->pid) { - _D("remove trusted busname item(%s, %s)", item->app_id, item->bus_name); - free(item->app_id); - free(item->bus_name); - free(item); - g_hash_table_iter_remove(&iter); - } - } - } - - return 0; -} - static int __esd_init() { int req_id = 0; @@ -1775,7 +1947,7 @@ static int __esd_init() #endif ecore_init(); - aul_listen_app_dead_signal(__esd_app_dead_handler, NULL); + __esd_init_cynara(); pkgmgr_client *client = pkgmgr_client_new(PC_LISTENING); if (client == NULL) { @@ -1825,6 +1997,8 @@ static void __esd_finalize(void) _D("esd finalize"); + __esd_stop_sd_monitor(); + if (trusted_busname_table) { GHashTableIter iter; @@ -1899,6 +2073,8 @@ static void __esd_finalize(void) } } + __esd_finish_cynara(); + _D("esd finalize end"); } -- 2.7.4 From 3900fe2afc11ff41b1b7e4bcbc5326d6cb52b47b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Oskar=20=C5=9Awitalski?= Date: Tue, 8 Dec 2015 09:15:25 +0100 Subject: [PATCH 04/16] Fix memory leak MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Strings from Cynara gdbus helper lib should be freed with g_free() Change-Id: I1131bb38026961c7abe27f46b6eafa2c025744c2 Signed-off-by: Oskar Świtalski --- src/esd_main.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/esd_main.c b/src/esd_main.c index 2093cf5..ba3dd4e 100644 --- a/src/esd_main.c +++ b/src/esd_main.c @@ -1450,6 +1450,9 @@ static void check_privilege_valid_method_call(GDBusConnection *connection, const } out: + g_free(client); + g_free(user); + g_free(session); param = g_variant_new("(i)", result); _D("event_name(%s), result(%d)", event_name, result); g_dbus_method_invocation_return_value(invocation, param); -- 2.7.4 From 07d65260664ce5f90543bf0bd2005f7ca4a3a0f3 Mon Sep 17 00:00:00 2001 From: jongmyeongko Date: Wed, 9 Dec 2015 11:59:49 +0900 Subject: [PATCH 05/16] bugfix of getting appid and checking privilege via gdbus helper of cynara Change-Id: Ia967bc04751492fb57a067fb9169c6e0369f8ae4 Signed-off-by: jongmyeongko --- src/esd_main.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/esd_main.c b/src/esd_main.c index ba3dd4e..931c33d 100644 --- a/src/esd_main.c +++ b/src/esd_main.c @@ -74,10 +74,10 @@ static bool g_is_bootcompleted = false; static GHashTable *trusted_busname_table; /* table of dbus bus-names for trusted user-event */ typedef struct __trusted_busname_item { - uid_t uid; char *app_id; char *bus_name; int pid; + uid_t uid; } trusted_item; typedef struct __eventlaunch_item_param { @@ -85,17 +85,17 @@ typedef struct __eventlaunch_item_param { } eventlaunch_item_param_s; typedef struct esd_list_item { - uid_t uid; char *pkg_id; char *app_id; + uid_t uid; } esd_list_item_s; typedef struct __event_launch_table_item { - uid_t uid; char *event_name; char *package_name; /* just for passing pointer to app-list removal func */ GList *app_list_evtlaunch; /* app-list for on-event-launch */ guint reg_id; + uid_t uid; } event_launch_item; enum __pkg_event_type { @@ -258,7 +258,7 @@ static int __esd_check_certificate_match(uid_t uid, const char *app_id, uid_t fr pkgmgrinfo_cert_compare_result_type_e res; int ret = 0; - _D("uid(%d), app_id(%s), from_uid(%d), from_appid(%s)", uid, app_id, from_appid); + _D("uid(%d), app_id(%s), from_uid(%d), from_appid(%s)", uid, app_id, from_uid, from_appid); if (uid != from_uid) { /* TODO(jongmyeong.ko): check cert result if uids are not same */ @@ -1174,7 +1174,7 @@ static int __esd_get_appid_by_pid(int pid, uid_t uid, char *app_id, int buf_size _E("invalid uid(%d)", uid); retval = ES_R_ERROR; } else { - ret = aul_app_get_pkgid_bypid_for_uid(pid, app_id, buf_size, (uid_t)uid); + ret = aul_app_get_appid_bypid_for_uid(pid, app_id, buf_size, (uid_t)uid); if (ret != AUL_R_OK) { _E("failed to get appid by pid"); retval = ES_R_ERROR; @@ -1418,14 +1418,14 @@ static void check_privilege_valid_method_call(GDBusConnection *connection, const if (__esd_get_appid_by_pid(sender_pid, sender_uid, app_id, sizeof(app_id)) < 0) { result = ES_R_ERROR; } else { - ret = cynara_creds_gdbus_get_client(connection, sender, CLIENT_METHOD_PID, &client); + ret = cynara_creds_gdbus_get_client(connection, sender, CLIENT_METHOD_DEFAULT, &client); if (ret != CYNARA_API_SUCCESS) { _E("failed to get client"); result = ES_R_EINVAL; goto out; } - ret = cynara_creds_gdbus_get_user(connection, sender, USER_METHOD_UID, &user); + ret = cynara_creds_gdbus_get_user(connection, sender, USER_METHOD_DEFAULT, &user); if (ret != CYNARA_API_SUCCESS) { _E("failed to get user"); result = ES_R_EINVAL; @@ -1439,6 +1439,7 @@ static void check_privilege_valid_method_call(GDBusConnection *connection, const goto out; } + _D("app_id(%s), client(%s), session(%s), user(%s)", app_id, client, session, user); if (__esd_check_valid_privilege_by_cynara(app_id, client, session, user, privilege_name)) { result = 1; } else { -- 2.7.4 From 738c498b0612eef7a77744438742949b8dc505b6 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Tue, 12 Jan 2016 18:33:22 +0900 Subject: [PATCH 06/16] Adjust coding rule Change-Id: I716525bce2ad5c74df6f044819de522cf8246925 Signed-off-by: Hwankyu Jhun --- src/esd_main.c | 275 ++++++++++++++++++++++++------------------------- src/esd_system_event.c | 129 +++++++++-------------- 2 files changed, 180 insertions(+), 224 deletions(-) diff --git a/src/esd_main.c b/src/esd_main.c index 931c33d..c85bb70 100644 --- a/src/esd_main.c +++ b/src/esd_main.c @@ -162,9 +162,8 @@ static int __esd_check_earlier_support(const char *event_name) int size = sizeof(earlier_event_list)/sizeof(*earlier_event_list); for (i = 0; i < size; i++) { - if (strcmp(earlier_event_list[i], event_name) == 0) { + if (strcmp(earlier_event_list[i], event_name) == 0) return true; - } } return false; @@ -177,9 +176,8 @@ static int __esd_check_event_launch_support(const char *event_name) int size = sizeof(event_launch_support_list)/sizeof(*event_launch_support_list); for (i = 0; i < size; i++) { - if (strcmp(event_launch_support_list[i], event_name) == 0) { + if (strcmp(event_launch_support_list[i], event_name) == 0) return true; - } } return false; @@ -244,9 +242,8 @@ static uid_t __get_sender_uid(GDBusConnection *conn, const char *sender_name) uid_t uid = -1; uid = __get_sender_unixinfo(conn, sender_name, "GetConnectionUnixUser"); - if (uid < 0) { + if (uid < 0) _E("failed to get uid"); - } _D("sender_name(%s), uid(%d)", sender_name, uid); @@ -302,15 +299,15 @@ static bool __esd_check_application_validation(uid_t uid, const char *appid) static void __esd_trusted_busname_print_items(void) { GHashTableIter iter; - gpointer key, value; + gpointer key; + gpointer value; g_hash_table_iter_init(&iter, trusted_busname_table); while (g_hash_table_iter_next(&iter, &key, &value)) { trusted_item *item = (trusted_item *)value; - if (item) { + if (item) _D("uid(%d), appid(%s), pid(%d), busname(%s)", item->uid, item->app_id, item->pid, item->bus_name); - } } } @@ -319,6 +316,7 @@ static int __esd_trusted_busname_add_item(uid_t uid, const char *appid, const ch char *app_id = NULL; char *bus_name = NULL; trusted_item *item = NULL; + trusted_item *new_item; app_id = strdup(appid); if (app_id == NULL) { @@ -341,7 +339,7 @@ static int __esd_trusted_busname_add_item(uid_t uid, const char *appid, const ch FREE_AND_NULL(app_id); FREE_AND_NULL(bus_name); } else { - trusted_item *new_item = calloc(1, sizeof(trusted_item)); + new_item = calloc(1, sizeof(trusted_item)); if (new_item == NULL) { _E("memory alloc failed"); FREE_AND_NULL(app_id); @@ -411,9 +409,8 @@ static int __esd_check_trusted_events(GDBusConnection *conn, const char *list_na if (__esd_check_application_validation(uid, tmp_appid)) { _D("add to table"); ret = __esd_trusted_busname_add_item(uid, tmp_appid, (const char *)str, pid); - if (ret < 0) { + if (ret < 0) _E("failed to add item"); - } } } g_variant_iter_free(iter); @@ -460,6 +457,7 @@ static bool __esd_check_valid_privilege_by_cynara(const char *appid, const char return has_privilege; } +#if 0 static int __esd_privilege_func(const char *name, void *user_data) { esd_privilege_check *epc = (esd_privilege_check *)user_data; @@ -472,12 +470,12 @@ static int __esd_privilege_func(const char *name, void *user_data) return 0; } } +#endif static int __esd_check_app_privileged_event(uid_t uid, const char *appid, const char *pkgid, const char *event_name) { char *privilege_name = NULL; char client[256] = {0, }; - char *session = NULL; char *user = NULL; int retval = 1; @@ -488,7 +486,6 @@ static int __esd_check_app_privileged_event(uid_t uid, const char *appid, const if (privilege_name) { /* TODO(jongmyeong.ko): getting client should be replaced by cynara api */ snprintf(client, 256, "User::App::%s", pkgid); - session = ""; user = (char *)g_strdup_printf("%u", uid); if (!__esd_check_valid_privilege_by_cynara(appid, client, "", user, privilege_name)) { _E("app(%s) has NOT privilege(%s)", appid, privilege_name); @@ -518,13 +515,13 @@ static void __esd_print_interested_event(gpointer data, gpointer user_data) static void __esd_launch_table_print_items(void) { GHashTableIter iter; - gpointer key, value; + gpointer key; + gpointer value; g_hash_table_iter_init(&iter, event_launch_table); - while (g_hash_table_iter_next(&iter, &key, &value)) { + while (g_hash_table_iter_next(&iter, &key, &value)) __esd_print_interested_event(value, NULL); - } } static int __esd_find_compare_by_list_item(gconstpointer data, gconstpointer user_data) @@ -563,7 +560,7 @@ static int __esd_add_launch_item(uid_t uid, const char *event_name, const char * char *app_id = NULL; char *pkg_id = NULL; esd_list_item_s *item_of_list = NULL; - + event_launch_item *eli; event_launch_item *el_item = (event_launch_item *)g_hash_table_lookup(event_launch_table, event_name); @@ -602,7 +599,7 @@ static int __esd_add_launch_item(uid_t uid, const char *event_name, const char * } } else { _D("add new item (all)"); - event_launch_item *eli = calloc(1, sizeof(event_launch_item)); + eli = calloc(1, sizeof(event_launch_item)); if (!eli) { _E("memory alloc failed"); return ES_R_ENOMEM; @@ -671,7 +668,8 @@ static void __esd_remove_all_private_usr_app_list(gpointer data, gpointer user_d static int __esd_launch_table_remove_private_usr_items(void) { GHashTableIter iter; - gpointer key, value; + gpointer key; + gpointer value; event_launch_item *eli = NULL; GList *first_list = NULL; @@ -683,9 +681,9 @@ static int __esd_launch_table_remove_private_usr_items(void) first_list = g_list_first(eli->app_list_evtlaunch); if (first_list == NULL) { - if (eli->reg_id) { + if (eli->reg_id) eventsystem_unregister_event(eli->reg_id); - } + g_hash_table_iter_remove(&iter); } } @@ -699,9 +697,8 @@ static void __esd_remove_app_list(gpointer data, gpointer user_data) esd_list_item_s *item = (esd_list_item_s *)data; event_launch_item *eli = (event_launch_item *)user_data; - if (eli->uid != GLOBAL_USER && eli->uid != item->uid) { + if (eli->uid != GLOBAL_USER && eli->uid != item->uid) skip = true; - } if (!skip && !strcmp(eli->package_name, item->pkg_id)) { _D("pkg_id(%s), app_id(%s)", eli->package_name, item->app_id); @@ -721,9 +718,9 @@ static int __esd_remove_launch_item(uid_t uid, gpointer data, const char *pkg_id first_list = g_list_first(eli->app_list_evtlaunch); if (first_list == NULL) { - if (eli->reg_id) { + if (eli->reg_id) eventsystem_unregister_event(eli->reg_id); - } + return ES_R_REMOVE; } @@ -733,7 +730,8 @@ static int __esd_remove_launch_item(uid_t uid, gpointer data, const char *pkg_id static int __esd_launch_table_remove_items(uid_t uid, const char *pkg_id) { GHashTableIter iter; - gpointer key, value; + gpointer key; + gpointer value; g_hash_table_iter_init(&iter, event_launch_table); @@ -751,13 +749,15 @@ static void __esd_event_launch_with_appid(gpointer data, gpointer user_data) { esd_list_item_s *item = (esd_list_item_s *)data; uid_t uid = item->uid; - uid_t from_uid = 0; char *app_id = item->app_id; esd_event_param *eep = (esd_event_param *)user_data; - char *from_appid = (char *)eep->user_data; static unsigned int req_id; int pid; - int ret = 0; + char event_uri[1024]; + bundle *b; + /* char *from_appid = (char *)eep->user_data; */ + /* uid_t from_uid = 0; */ + /* int ret = 0; */ _D("launch_on_event: app_id(%s), event_name(%s)", app_id, eep->event_name); @@ -777,9 +777,8 @@ static void __esd_event_launch_with_appid(gpointer data, gpointer user_data) if (!aul_app_is_running(app_id)) { */ if (1) { - char event_uri[1024] = {0, }; - snprintf(event_uri, 1024, "event://%s", eep->event_name); - bundle *b = bundle_dup(eep->event_data); + snprintf(event_uri, sizeof(event_uri), "event://%s", eep->event_name); + b = bundle_dup(eep->event_data); appsvc_set_operation(b, APPSVC_OPERATION_LAUNCH_ON_EVENT); appsvc_set_uri(b, event_uri); appsvc_set_appid(b, app_id); @@ -806,48 +805,47 @@ static void __esd_check_event_launch_with_eventid(gpointer data, gpointer user_d static void __esd_launch_event_handler(char *event_name, bundle *data, void *user_data) { - _D("event_name(%s)", event_name); + const char *val; + const char *msg_type; + const char *msg_id; + esd_event_param *eep; + event_launch_item *el_item; - event_launch_item *el_item = - (event_launch_item *)g_hash_table_lookup(event_launch_table, event_name); + _D("event_name(%s)", event_name); - if (el_item == NULL) { + el_item = (event_launch_item *)g_hash_table_lookup(event_launch_table, event_name); + if (el_item == NULL) return; - } if (el_item->app_list_evtlaunch != NULL) { if (strcmp(SYS_EVENT_BATTERY_CHARGER_STATUS, event_name) == 0) { - const char *val = bundle_get_val(data, EVT_KEY_BATTERY_CHARGER_STATUS); + val = bundle_get_val(data, EVT_KEY_BATTERY_CHARGER_STATUS); _D("charger val(%s)", val); - if (strcmp(EVT_VAL_BATTERY_CHARGER_CONNECTED, val) != 0) { + if (strcmp(EVT_VAL_BATTERY_CHARGER_CONNECTED, val) != 0) return; - } } else if (strcmp(SYS_EVENT_USB_STATUS, event_name) == 0) { - const char *val = bundle_get_val(data, EVT_KEY_USB_STATUS); + val = bundle_get_val(data, EVT_KEY_USB_STATUS); _D("usb val(%s)", val); - if (strcmp(EVT_VAL_USB_CONNECTED, val) != 0) { + if (strcmp(EVT_VAL_USB_CONNECTED, val) != 0) return; - } } else if (strcmp(SYS_EVENT_EARJACK_STATUS, event_name) == 0) { - const char *val = bundle_get_val(data, EVT_KEY_EARJACK_STATUS); + val = bundle_get_val(data, EVT_KEY_EARJACK_STATUS); _D("earjack val(%s)", val); - if (strcmp(EVT_VAL_EARJACK_CONNECTED, val) != 0) { + if (strcmp(EVT_VAL_EARJACK_CONNECTED, val) != 0) return; - } } else if (strcmp(SYS_EVENT_INCOMMING_MSG, event_name) == 0) { - const char *msg_type = bundle_get_val(data, EVT_KEY_MSG_TYPE); + msg_type = bundle_get_val(data, EVT_KEY_MSG_TYPE); _D("msg_type(%s)", msg_type); - if (msg_type == NULL) { + if (msg_type == NULL) return; - } - const char *msg_id = bundle_get_val(data, EVT_KEY_MSG_ID); + + msg_id = bundle_get_val(data, EVT_KEY_MSG_ID); _D("msg_id(%s)", msg_id); - if (msg_id == NULL) { + if (msg_id == NULL) return; - } } - esd_event_param *eep = calloc(1, sizeof(esd_event_param)); + eep = calloc(1, sizeof(esd_event_param)); if (!eep) { _E("memory alloc failed"); return; @@ -865,26 +863,28 @@ static void __esd_print_earlier_event(gpointer data, gpointer user_data) { earlier_item *item = (earlier_item *)data; char *event_name = (char *)item->event_name; + const char *val; + _D("event_name = (%s)", event_name); if (strcmp(event_name, SYS_EVENT_BOOT_COMPLETED) == 0) { if (item->earlier_data) { - const char *val = bundle_get_val(item->earlier_data, EVT_KEY_BOOT_COMPLETED); + val = bundle_get_val(item->earlier_data, EVT_KEY_BOOT_COMPLETED); _D("boot_completed(%s)", val); } } else if (strcmp(event_name, SYS_EVENT_SYSTEM_SHUTDOWN) == 0) { if (item->earlier_data) { - const char *val = bundle_get_val(item->earlier_data, EVT_KEY_SYSTEM_SHUTDOWN); + val = bundle_get_val(item->earlier_data, EVT_KEY_SYSTEM_SHUTDOWN); _D("shutdown(%s)", val); } } else if (strcmp(event_name, SYS_EVENT_LOW_MEMORY) == 0) { if (item->earlier_data) { - const char *val = bundle_get_val(item->earlier_data, EVT_KEY_LOW_MEMORY); + val = bundle_get_val(item->earlier_data, EVT_KEY_LOW_MEMORY); _D("low_memory(%s)", val); } } else if (strcmp(event_name, SYS_EVENT_BATTERY_CHARGER_STATUS) == 0) { if (item->earlier_data) { - const char *val = bundle_get_val(item->earlier_data, EVT_KEY_BATTERY_CHARGER_STATUS); + val = bundle_get_val(item->earlier_data, EVT_KEY_BATTERY_CHARGER_STATUS); _D("charger_status(%s)", val); } } @@ -893,32 +893,32 @@ static void __esd_print_earlier_event(gpointer data, gpointer user_data) static void __esd_earlier_table_print_items(void) { GHashTableIter iter; - gpointer key, value; + gpointer key; + gpointer value; g_hash_table_iter_init(&iter, earlier_event_table); - while (g_hash_table_iter_next(&iter, &key, &value)) { + while (g_hash_table_iter_next(&iter, &key, &value)) __esd_print_earlier_event(value, NULL); - } } static void __esd_earlier_event_handler(char *event_name, bundle *data, void *user_data) { + int handle; + earlier_item *item; _D("event_name(%s)", event_name); - earlier_item *item = - (earlier_item *)g_hash_table_lookup(earlier_event_table, event_name); - + item = (earlier_item *)g_hash_table_lookup(earlier_event_table, event_name); if (item) { /* update earlier value */ - if (item->earlier_data != NULL) { + if (item->earlier_data != NULL) bundle_free(item->earlier_data); - } + item->earlier_data = bundle_dup(data); if (!g_is_bootcompleted) { if (strcmp(event_name, SYS_EVENT_BOOT_COMPLETED) == 0) { - int handle = creat(ESD_BOOT_COMPLETED, 0640); + handle = creat(ESD_BOOT_COMPLETED, 0640); if (handle != -1) close(handle); g_is_bootcompleted = true; @@ -933,25 +933,25 @@ static void __esd_event_handler(char *event_name, bundle *data, void *user_data) _D("event_name(%s)", event_name); #ifdef APPFW_EVENT_SYSTEM_EARLIER_FEATURE - if (__esd_check_earlier_support(event_name)) { + if (__esd_check_earlier_support(event_name)) __esd_earlier_event_handler(event_name, data, user_data); - } #endif - if (__esd_check_event_launch_support(event_name)) { + if (__esd_check_event_launch_support(event_name)) __esd_launch_event_handler(event_name, data, user_data); - } } static void __esd_trusted_busname_remove_item(char *bus_name) { GHashTableIter iter; - gpointer key, value; + gpointer key; + gpointer value; + trusted_item *item; g_hash_table_iter_init(&iter, trusted_busname_table); while (g_hash_table_iter_next(&iter, &key, &value)) { - trusted_item *item = (trusted_item *)value; + item = (trusted_item *)value; if (item) { if (strcmp(bus_name, item->bus_name) == 0) { _D("remove trusted busname item(%s, %s)", item->app_id, item->bus_name); @@ -986,13 +986,12 @@ static void __esd_filter_name_owner_changed(GDBusConnection *connection, _D("changed name(%s), old_onwer(%s)(%d) -> new_onwer(%s)(%d)", name, old_owner, old_len, new_owner, new_len); - if (old_len > 0 && new_len == 0) { + if (old_len > 0 && new_len == 0) __esd_trusted_busname_remove_item(name); - } else if (old_len == 0 && new_len > 0) { + else if (old_len == 0 && new_len > 0) _D("new name owned"); - } else { + else _E("not-expected name change"); - } } } @@ -1033,9 +1032,8 @@ static int __esd_get_user_items(void) _I("found uid(%d)", cur_uid); ret = pkgmgrinfo_appinfo_get_usr_installed_list(__esd_add_appinfo_handler, cur_uid, &cur_uid); - if (ret < 0) { + if (ret < 0) _E("failed to get user(%d)-app list (%d)", cur_uid, ret); - } } } @@ -1060,9 +1058,8 @@ static int __esd_start_sd_monitor(void) int fd = 0; ret = __esd_get_user_items(); - if (ret < 0) { + if (ret < 0) return ES_R_ERROR; - } ret = sd_login_monitor_new("uid", &g_sd_monitor); if (ret < 0) { @@ -1314,6 +1311,7 @@ static void get_trusted_peer_method_call(GDBusConnection *connection, const gcha uid_t uid = 0; char *_appid = NULL; char *_busname = NULL; + trusted_item *item; g_variant_get(parameters, "(s)", &event_name); _D("event_name(%s)", event_name); @@ -1327,19 +1325,17 @@ static void get_trusted_peer_method_call(GDBusConnection *connection, const gcha g_hash_table_iter_init(&iter, trusted_busname_table); while (g_hash_table_iter_next(&iter, &key, &value)) { - trusted_item *item = (trusted_item *)value; + item = (trusted_item *)value; uid = item->uid; _appid = item->app_id; _busname = item->bus_name; - if (uid != GLOBAL_USER && uid != sender_uid) { + if (uid != GLOBAL_USER && uid != sender_uid) continue; - } ret = __esd_check_certificate_match(uid, _appid, sender_uid, app_id); - if (ret == ES_R_OK) { + if (ret == ES_R_OK) g_variant_builder_add(builder, "s", _busname); - } } result = 1; @@ -1348,9 +1344,8 @@ static void get_trusted_peer_method_call(GDBusConnection *connection, const gcha param = g_variant_new("(ias)", result, builder); _D("result(%d)", result); g_dbus_method_invocation_return_value(invocation, param); - if (builder) { + if (builder) g_variant_builder_unref(builder); - } } static void setup_trusted_peer_method_call(GDBusConnection *connection, const gchar *sender, @@ -1440,11 +1435,10 @@ static void check_privilege_valid_method_call(GDBusConnection *connection, const } _D("app_id(%s), client(%s), session(%s), user(%s)", app_id, client, session, user); - if (__esd_check_valid_privilege_by_cynara(app_id, client, session, user, privilege_name)) { + if (__esd_check_valid_privilege_by_cynara(app_id, client, session, user, privilege_name)) result = 1; - } else { + else result = ES_R_EINVAL; - } } } else { result = 1; @@ -1468,6 +1462,7 @@ static void get_earlier_data_method_call(GVariant *parameters, GDBusMethodInvoca bundle *b = NULL; bundle_raw *raw = NULL; int len = 0; + earlier_item *item; g_variant_get(parameters, "(s)", &event_name); @@ -1479,9 +1474,7 @@ static void get_earlier_data_method_call(GVariant *parameters, GDBusMethodInvoca result = ES_R_ERROR; } - earlier_item *item = - (earlier_item *)g_hash_table_lookup(earlier_event_table, event_name); - + item = (earlier_item *)g_hash_table_lookup(earlier_event_table, event_name); if (item != NULL) { if (item->earlier_data) { b = bundle_dup(item->earlier_data); @@ -1551,12 +1544,14 @@ static void __esd_on_bus_acquired(GDBusConnection *connection, static void __esd_on_name_acquired(GDBusConnection *connection, const gchar *name, gpointer user_data) { + bundle *b; + _I("name acquired(%s)", name); __esd_check_trusted_events(connection, "ListNames"); __esd_check_trusted_events(connection, "ListActivatableNames"); - bundle *b = bundle_create(); + b = bundle_create(); bundle_add_str(b, EVT_KEY_ESD_STATUS, EVT_VAL_ESD_STARTED); eventsystem_send_system_event(SYS_EVENT_ESD_STATUS, b); bundle_free(b); @@ -1580,21 +1575,30 @@ static int __esd_before_loop(void) { int ret = 0; uid_t uid = 0; + GError *error = NULL; + guint owner_id = 0; #ifdef APPFW_EVENT_SYSTEM_EARLIER_FEATURE guint subscription_id = 0; - int i, size; + int i; + int size; + char *event_name; + int fd; + int val; + int status; + int charger_status; + int charge_now; + ealier_item *item; earlier_event_table = g_hash_table_new(g_str_hash, g_str_equal); _I("register events for earlier_data"); size = sizeof(earlier_event_list)/sizeof(*earlier_event_list); for (i = 0; i < size; i++) { - char *event_name = NULL; event_name = (char *)earlier_event_list[i]; _I("event_name(%s)", event_name); - earlier_item *item = calloc(1, sizeof(earlier_item)); + item = calloc(1, sizeof(earlier_item)); if (item == NULL) { _E("memery alloc failed"); return ES_R_ENOMEM; @@ -1608,7 +1612,6 @@ static int __esd_before_loop(void) /* set initial data */ if (strcmp(event_name, SYS_EVENT_BOOT_COMPLETED) == 0) { - int fd = 0; fd = open(ESD_BOOT_COMPLETED, O_RDONLY); if (fd < 0) { _D("open file error(%d)", fd); @@ -1619,7 +1622,6 @@ static int __esd_before_loop(void) close(fd); } } else if (strcmp(event_name, SYS_EVENT_SYSTEM_SHUTDOWN) == 0) { - int val; ret = vconf_get_int(VCONFKEY_SYSMAN_POWER_OFF_STATUS, &val); if (ret != VCONF_OK) { _E("failed to get power_off status (%d)", ret); @@ -1633,7 +1635,6 @@ static int __esd_before_loop(void) } } } else if (strcmp(event_name, SYS_EVENT_LOW_MEMORY) == 0) { - int status; ret = vconf_get_int(VCONFKEY_SYSMAN_LOW_MEMORY, &status); if (ret != VCONF_OK) { _E("failed to get low_memory status (%d)", ret); @@ -1650,16 +1651,13 @@ static int __esd_before_loop(void) EVT_VAL_MEMORY_NORMAL); } } else if (strcmp(event_name, SYS_EVENT_BATTERY_CHARGER_STATUS) == 0) { - int charger_status; - int charge_now; ret = vconf_get_int(VCONFKEY_SYSMAN_CHARGER_STATUS, &charger_status); if (ret != VCONF_OK) { _E("failed to get charger_status (%d)", ret); } else { ret = vconf_get_int(VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW, &charge_now); - if (ret != VCONF_OK) { + if (ret != VCONF_OK) _E("failed to get charge_now (%d)", ret); - } } if (ret == VCONF_OK) { @@ -1682,7 +1680,6 @@ static int __esd_before_loop(void) } } - eventsystem_register_event(event_name, &subscription_id, (eventsystem_handler)__esd_event_handler, NULL); if (subscription_id == 0) { @@ -1720,10 +1717,6 @@ static int __esd_before_loop(void) trusted_busname_table = g_hash_table_new(g_str_hash, g_str_equal); /* gdbus setup for method call */ - GError *error = NULL; - guint owner_id = 0; - - error = NULL; introspection_data = g_dbus_node_info_new_for_xml(introspection_xml, &error); if (!introspection_data) { _E("g_dbus_node_info_new_for_xml error(%s)", error->message); @@ -1789,9 +1782,8 @@ static int __esd_appcontrol_cb(const char *operation, } else if (!__esd_check_app_privileged_event(uid, appid, pkgid, event_name)) { _E("failed to add item (no privilege)"); } else { - if (__esd_add_launch_item(uid, event_name, appid, pkgid)) { + if (__esd_add_launch_item(uid, event_name, appid, pkgid)) _E("failed to add item"); - } } FREE_AND_NULL(event_name); } else { @@ -1933,9 +1925,8 @@ static int __esd_pkgmgr_event_callback(uid_t target_uid, int req_id, const char _E("pkg_event(%d) falied", pkg_event->type); __esd_pkgmgr_event_free(pkg_event); } else { - if (strcmp(key, "install_percent") != 0) { + if (strcmp(key, "install_percent") != 0) __esd_pkgmgr_event_free(pkg_event); - } } return 0; @@ -1945,6 +1936,8 @@ static int __esd_init() { int req_id = 0; int ret = 0; + pkgmgr_client *client; + esd_pkgmgr_event *pkg_event; #if (GLIB_MAJOR_VERSION <= 2 && GLIB_MINOR_VERSION < 36) g_type_init(); @@ -1953,19 +1946,19 @@ static int __esd_init() __esd_init_cynara(); - pkgmgr_client *client = pkgmgr_client_new(PC_LISTENING); + client = pkgmgr_client_new(PC_LISTENING); if (client == NULL) { _E("set pkgmgr client failed"); return ES_R_ERROR; } - esd_pkgmgr_event *pkg_event = calloc(1, sizeof(esd_pkgmgr_event)); + pkg_event = calloc(1, sizeof(esd_pkgmgr_event)); if (pkg_event == NULL) { _E("memory alloc failed"); ret = pkgmgr_client_free(client); - if (ret != PKGMGR_R_OK) { + if (ret != PKGMGR_R_OK) _E("pkgmgr_client_free failed(%d)", ret); - } + return ES_R_ENOMEM; } @@ -1973,9 +1966,9 @@ static int __esd_init() if (req_id < 0) { _E("pkgmgr client listen failed"); ret = pkgmgr_client_free(client); - if (ret != PKGMGR_R_OK) { + if (ret != PKGMGR_R_OK) _E("pkgmgr_client_free failed(%d)", ret); - } + return ES_R_ERROR; } @@ -1996,20 +1989,24 @@ static void __esd_remove_esd_list_item(gpointer data, gpointer user_data) static void __esd_finalize(void) { - gpointer key, value; + gpointer key; + gpointer value; + GHashTableIter iter; + trusted_item *item; + event_launch_item *el_item; int ret = 0; +#ifdef APPFW_EVENT_SYSTEM_EARLIER_FEATURE + earlier_item *er_item; +#endif _D("esd finalize"); __esd_stop_sd_monitor(); if (trusted_busname_table) { - GHashTableIter iter; - g_hash_table_iter_init(&iter, trusted_busname_table); - while (g_hash_table_iter_next(&iter, &key, &value)) { - trusted_item *item = (trusted_item *)value; + item = (trusted_item *)value; if (item) { free(item->app_id); free(item->bus_name); @@ -2024,19 +2021,16 @@ static void __esd_finalize(void) #ifdef APPFW_EVENT_SYSTEM_EARLIER_FEATURE if (earlier_event_table) { - GHashTableIter iter; - g_hash_table_iter_init(&iter, earlier_event_table); - while (g_hash_table_iter_next(&iter, &key, &value)) { - earlier_item *item = (earlier_item *)value; - if (item) { - eventsystem_unregister_event(item->reg_id); - free(item->event_name); - bundle_free(item->earlier_data); - free(item); + er_item = (earlier_item *)value; + if (er_item) { + eventsystem_unregister_event(er_item->reg_id); + free(er_item->event_name); + bundle_free(er_item->earlier_data); + free(er_item); } else { - _E("item is NULL"); + _E("ealier item is NULL"); } g_hash_table_iter_remove(&iter); } @@ -2045,12 +2039,9 @@ static void __esd_finalize(void) #endif if (event_launch_table) { - GHashTableIter iter; - g_hash_table_iter_init(&iter, event_launch_table); - while (g_hash_table_iter_next(&iter, &key, &value)) { - event_launch_item *el_item = (event_launch_item *)value; + el_item = (event_launch_item *)value; if (el_item) { eventsystem_unregister_event(el_item->reg_id); free(el_item->event_name); @@ -2066,15 +2057,13 @@ static void __esd_finalize(void) g_hash_table_unref(event_launch_table); } - if (introspection_data) { + if (introspection_data) g_dbus_node_info_unref(introspection_data); - } if (s_info.client) { ret = pkgmgr_client_free(s_info.client); - if (ret != PKGMGR_R_OK) { + if (ret != PKGMGR_R_OK) _E("pkgmgr_client_free failed(%d)", ret); - } } __esd_finish_cynara(); diff --git a/src/esd_system_event.c b/src/esd_system_event.c index 5579ac5..339833b 100644 --- a/src/esd_system_event.c +++ b/src/esd_system_event.c @@ -43,9 +43,8 @@ static int __esd_event_data_compare(bundle *b1, bundle *b2, const char *key) ret = 1; } - if (ret == 0) { + if (ret == 0) _D("same event_data"); - } return ret; } @@ -53,7 +52,6 @@ static int __esd_event_data_compare(bundle *b1, bundle *b2, const char *key) static int __esd_send_system_event(const char *event_name, bundle *b, const char *key) { int ret = ES_R_OK; - esd_sent_item *item = (esd_sent_item *)g_hash_table_lookup(esd_sent_table, event_name); @@ -111,22 +109,19 @@ static void __esd_vconfcb_location_use_mylocation(keynode_t *node, void *user_da key = EVT_KEY_LOCATION_ENABLE_STATE; - if (enabled) { + if (enabled) val = EVT_VAL_LOCATION_ENABLED; - } else { + else val = EVT_VAL_LOCATION_DISABLED; - } b = bundle_create(); bundle_add_str(b, key, val); - if (__esd_send_system_event(SYS_EVENT_LOCATION_ENABLE_STATE, b, key) != ES_R_OK) { + if (__esd_send_system_event(SYS_EVENT_LOCATION_ENABLE_STATE, b, key) != ES_R_OK) _E("failed to send event"); - } - if (b) { + if (b) bundle_free(b); - } } static void __esd_vconfcb_location_enabled(keynode_t *node, void *user_data) @@ -147,22 +142,19 @@ static void __esd_vconfcb_location_enabled(keynode_t *node, void *user_data) key = EVT_KEY_GPS_ENABLE_STATE; - if (enabled) { + if (enabled) val = EVT_VAL_GPS_ENABLED; - } else { + else val = EVT_VAL_GPS_DISABLED; - } b = bundle_create(); bundle_add_str(b, key, val); - if (__esd_send_system_event(SYS_EVENT_GPS_ENABLE_STATE, b, key) != ES_R_OK) { + if (__esd_send_system_event(SYS_EVENT_GPS_ENABLE_STATE, b, key) != ES_R_OK) _E("failed to send event"); - } - if (b) { + if (b) bundle_free(b); - } } static void __esd_vconfcb_location_network_enabled(keynode_t *node, void *user_data) @@ -183,22 +175,19 @@ static void __esd_vconfcb_location_network_enabled(keynode_t *node, void *user_d key = EVT_KEY_NPS_ENABLE_STATE; - if (enabled) { + if (enabled) val = EVT_VAL_NPS_ENABLED; - } else { + else val = EVT_VAL_NPS_DISABLED; - } b = bundle_create(); bundle_add_str(b, key, val); - if (__esd_send_system_event(SYS_EVENT_NPS_ENABLE_STATE, b, key) != ES_R_OK) { + if (__esd_send_system_event(SYS_EVENT_NPS_ENABLE_STATE, b, key) != ES_R_OK) _E("failed to send event"); - } - if (b) { + if (b) bundle_free(b); - } } static void __esd_vconfcb_language_set(keynode_t *node, void *user_data) @@ -220,13 +209,11 @@ static void __esd_vconfcb_language_set(keynode_t *node, void *user_data) b = bundle_create(); bundle_add_str(b, key, str); - if (__esd_send_system_event(SYS_EVENT_LANGUAGE_SET, b, key) != ES_R_OK) { + if (__esd_send_system_event(SYS_EVENT_LANGUAGE_SET, b, key) != ES_R_OK) _E("failed to send event"); - } - if (b) { + if (b) bundle_free(b); - } } static void __esd_vconfcb_hour_format(keynode_t *node, void *user_data) @@ -255,13 +242,11 @@ static void __esd_vconfcb_hour_format(keynode_t *node, void *user_data) b = bundle_create(); bundle_add_str(b, key, val); - if (__esd_send_system_event(SYS_EVENT_HOUR_FORMAT, b, key) != ES_R_OK) { + if (__esd_send_system_event(SYS_EVENT_HOUR_FORMAT, b, key) != ES_R_OK) _E("failed to send event"); - } - if (b) { + if (b) bundle_free(b); - } } static void __esd_vconfcb_region_format(keynode_t *node, void *user_data) @@ -283,13 +268,11 @@ static void __esd_vconfcb_region_format(keynode_t *node, void *user_data) b = bundle_create(); bundle_add_str(b, key, str); - if (__esd_send_system_event(SYS_EVENT_REGION_FORMAT, b, key) != ES_R_OK) { + if (__esd_send_system_event(SYS_EVENT_REGION_FORMAT, b, key) != ES_R_OK) _E("failed to send event"); - } - if (b) { + if (b) bundle_free(b); - } } static void __esd_vconfcb_vibration_status(keynode_t *node, void *user_data) @@ -320,46 +303,42 @@ static void __esd_vconfcb_vibration_status(keynode_t *node, void *user_data) val = EVT_VAL_VIBRATION_ON; b = bundle_create(); bundle_add_str(b, key, val); - if (__esd_send_system_event(SYS_EVENT_VIBRATION_STATE, b, key) != ES_R_OK) { + if (__esd_send_system_event(SYS_EVENT_VIBRATION_STATE, b, key) != ES_R_OK) _E("failed to send event"); - } - if (b) { + + if (b) bundle_free(b); - } key = EVT_KEY_SILENT_MODE; val = EVT_VAL_SILENTMODE_OFF; b = bundle_create(); bundle_add_str(b, key, val); - if (__esd_send_system_event(SYS_EVENT_SILENT_MODE, b, key) != ES_R_OK) { + if (__esd_send_system_event(SYS_EVENT_SILENT_MODE, b, key) != ES_R_OK) _E("failed to send event"); - } - if (b) { + + if (b) bundle_free(b); - } } else { key = EVT_KEY_VIBRATION_STATE; val = EVT_VAL_VIBRATION_OFF; b = bundle_create(); bundle_add_str(b, key, val); - if (__esd_send_system_event(SYS_EVENT_VIBRATION_STATE, b, key) != ES_R_OK) { + if (__esd_send_system_event(SYS_EVENT_VIBRATION_STATE, b, key) != ES_R_OK) _E("failed to send event"); - } - if (b) { + + if (b) bundle_free(b); - } if (!sound_on) { key = EVT_KEY_SILENT_MODE; val = EVT_VAL_SILENTMODE_ON; b = bundle_create(); bundle_add_str(b, key, val); - if (__esd_send_system_event(SYS_EVENT_SILENT_MODE, b, key) != ES_R_OK) { + if (__esd_send_system_event(SYS_EVENT_SILENT_MODE, b, key) != ES_R_OK) _E("failed to send event"); - } - if (b) { + + if (b) bundle_free(b); - } } } } @@ -392,35 +371,32 @@ static void __esd_vconfcb_sound_status(keynode_t *node, void *user_data) val = EVT_VAL_VIBRATION_OFF; b = bundle_create(); bundle_add_str(b, key, val); - if (__esd_send_system_event(SYS_EVENT_VIBRATION_STATE, b, key) != ES_R_OK) { + if (__esd_send_system_event(SYS_EVENT_VIBRATION_STATE, b, key) != ES_R_OK) _E("failed to send event"); - } - if (b) { + + if (b) bundle_free(b); - } key = EVT_KEY_SILENT_MODE; val = EVT_VAL_SILENTMODE_OFF; b = bundle_create(); bundle_add_str(b, key, val); - if (__esd_send_system_event(SYS_EVENT_SILENT_MODE, b, key) != ES_R_OK) { + if (__esd_send_system_event(SYS_EVENT_SILENT_MODE, b, key) != ES_R_OK) _E("failed to send event"); - } - if (b) { + + if (b) bundle_free(b); - } } else { if (!vibration_on) { key = EVT_KEY_SILENT_MODE; val = EVT_VAL_SILENTMODE_ON; b = bundle_create(); bundle_add_str(b, key, val); - if (__esd_send_system_event(SYS_EVENT_SILENT_MODE, b, key) != ES_R_OK) { + if (__esd_send_system_event(SYS_EVENT_SILENT_MODE, b, key) != ES_R_OK) _E("failed to send event"); - } - if (b) { + + if (b) bundle_free(b); - } } } } @@ -451,13 +427,11 @@ static void __esd_vconfcb_auto_rotate(keynode_t *node, void *user_data) b = bundle_create(); bundle_add_str(b, key, val); - if (__esd_send_system_event(SYS_EVENT_SCREEN_AUTOROTATE_STATE, b, key) != ES_R_OK) { + if (__esd_send_system_event(SYS_EVENT_SCREEN_AUTOROTATE_STATE, b, key) != ES_R_OK) _E("failed to send event"); - } - if (b) { + if (b) bundle_free(b); - } } static void __esd_vconfcb_mobiledata_state(keynode_t *node, void *user_data) @@ -486,13 +460,11 @@ static void __esd_vconfcb_mobiledata_state(keynode_t *node, void *user_data) b = bundle_create(); bundle_add_str(b, key, val); - if (__esd_send_system_event(SYS_EVENT_MOBILE_DATA_STATE, b, key) != ES_R_OK) { + if (__esd_send_system_event(SYS_EVENT_MOBILE_DATA_STATE, b, key) != ES_R_OK) _E("failed to send event"); - } - if (b) { + if (b) bundle_free(b); - } } static void __esd_vconfcb_roaming_state(keynode_t *node, void *user_data) @@ -521,13 +493,11 @@ static void __esd_vconfcb_roaming_state(keynode_t *node, void *user_data) b = bundle_create(); bundle_add_str(b, key, val); - if (__esd_send_system_event(SYS_EVENT_DATA_ROAMING_STATE, b, key) != ES_R_OK) { + if (__esd_send_system_event(SYS_EVENT_DATA_ROAMING_STATE, b, key) != ES_R_OK) _E("failed to send event"); - } - if (b) { + if (b) bundle_free(b); - } } static void __esd_vconfcb_font_set(keynode_t *node, void *user_data) @@ -549,13 +519,11 @@ static void __esd_vconfcb_font_set(keynode_t *node, void *user_data) b = bundle_create(); bundle_add_str(b, key, str); - if (__esd_send_system_event(SYS_EVENT_FONT_SET, b, key) != ES_R_OK) { + if (__esd_send_system_event(SYS_EVENT_FONT_SET, b, key) != ES_R_OK) _E("failed to send event"); - } - if (b) { + if (b) bundle_free(b); - } } static struct esd_vconf_handler vconf_callbacks[] = { @@ -600,4 +568,3 @@ int __esd_register_vconf_callbacks(void) return result; } - -- 2.7.4 From b763bae0f2249134048454c8e2d5d3dc91e4b07d Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Wed, 13 Jan 2016 07:34:25 +0900 Subject: [PATCH 07/16] Fix wrong declaration of the earlier_item pointer type Change-Id: I8dac8d69b3d968b46fc3bfe74e8101a8defc5b80 Signed-off-by: Hwankyu Jhun --- src/esd_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/esd_main.c b/src/esd_main.c index c85bb70..6d35c03 100644 --- a/src/esd_main.c +++ b/src/esd_main.c @@ -1588,7 +1588,7 @@ static int __esd_before_loop(void) int status; int charger_status; int charge_now; - ealier_item *item; + earlier_item *item; earlier_event_table = g_hash_table_new(g_str_hash, g_str_equal); -- 2.7.4 From 0e1ff1b9b1cb5cded132f8f6f189b8d1bdbb6cfd Mon Sep 17 00:00:00 2001 From: jongmyeongko Date: Tue, 2 Feb 2016 13:06:56 +0900 Subject: [PATCH 08/16] remove assert code. Change-Id: I70e5285b9492b203127a0b80ee34fcf6f9a76364 Signed-off-by: jongmyeongko --- src/esd_main.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/esd_main.c b/src/esd_main.c index 6d35c03..5488d15 100644 --- a/src/esd_main.c +++ b/src/esd_main.c @@ -6,7 +6,6 @@ #include #include #include -#include #include #include #include @@ -2077,14 +2076,12 @@ int main(int argc, char *argv[]) if (__esd_init() != 0) { _E("ESD Initialization failed!"); - assert(0); return ES_R_ERROR; } if (__esd_before_loop() < 0) { _E("ESD failed!"); __esd_finalize(); - assert(0); return ES_R_ERROR; } -- 2.7.4 From 2c80ceaa5fb9d98acb87c85b3baac06d3c60065d Mon Sep 17 00:00:00 2001 From: jongmyeongko Date: Fri, 19 Feb 2016 11:56:13 +0900 Subject: [PATCH 09/16] fix TODO items checking privilege by appid. checking app runnig status by uid. checking certficate for trusted event peers. Change-Id: I3b7a9d1fbbf211c95778ba7df8e399c2390c1af8 Signed-off-by: jongmyeongko --- CMakeLists.txt | 2 +- packaging/esd.spec | 1 + src/esd_main.c | 73 ++++++++++-------------------------------------------- 3 files changed, 15 insertions(+), 61 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0208eef..5d620f0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,7 +18,7 @@ INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/src) ### Required packages INCLUDE(FindPkgConfig) -pkg_check_modules(pkgs REQUIRED dlog bundle pkgmgr-info glib-2.0 gio-2.0 appsvc aul ecore vconf libtzplatform-config libsystemd-daemon cynara-client cynara-creds-gdbus cynara-session) +pkg_check_modules(pkgs REQUIRED dlog bundle pkgmgr-info glib-2.0 gio-2.0 appsvc aul ecore vconf libtzplatform-config libsystemd-daemon cynara-client cynara-creds-gdbus cynara-session security-manager) FOREACH(flag ${pkgs_CFLAGS}) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") diff --git a/packaging/esd.spec b/packaging/esd.spec index a84789f..74fd236 100644 --- a/packaging/esd.spec +++ b/packaging/esd.spec @@ -23,6 +23,7 @@ BuildRequires: pkgconfig(libsystemd-daemon) BuildRequires: pkgconfig(cynara-client) BuildRequires: pkgconfig(cynara-creds-gdbus) BuildRequires: pkgconfig(cynara-session) +BuildRequires: pkgconfig(security-manager) Requires(post): /sbin/ldconfig Requires(postun): /sbin/ldconfig diff --git a/src/esd_main.c b/src/esd_main.c index 5488d15..a21fade 100644 --- a/src/esd_main.c +++ b/src/esd_main.c @@ -18,6 +18,7 @@ #include #include #include +#include #include "eventsystem_daemon.h" #define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER) @@ -43,11 +44,6 @@ static const struct privilege_info privilege_check_list[] = { {SYS_EVENT_INCOMMING_MSG, "http://tizen.org/privilege/message.read"} }; -typedef struct __esd_privilege_check { - char *privilege_name; - int validation; -} esd_privilege_check; - static int privilege_check_size = sizeof(privilege_check_list)/sizeof(struct privilege_info); #ifdef APPFW_EVENT_SYSTEM_EARLIER_FEATURE @@ -256,12 +252,7 @@ static int __esd_check_certificate_match(uid_t uid, const char *app_id, uid_t fr _D("uid(%d), app_id(%s), from_uid(%d), from_appid(%s)", uid, app_id, from_uid, from_appid); - if (uid != from_uid) { - /* TODO(jongmyeong.ko): check cert result if uids are not same */ - _D("not same uid"); - } - - ret = pkgmgrinfo_pkginfo_compare_usr_app_cert_info(app_id, from_appid, uid, &res); + ret = pkgmgrinfo_pkginfo_compare_usr_app_cert_info(app_id, from_appid, from_uid, &res); if (ret < 0) { _E("failed to check certificate"); return ES_R_ERROR; @@ -286,11 +277,8 @@ static bool __esd_check_application_validation(uid_t uid, const char *appid) pkgmgrinfo_appinfo_destroy_appinfo(handle); - /* FIXME(jongmyeong.ko) */ - /* - if (!aul_app_is_running(appid)) + if (!aul_app_is_running_for_uid(appid, uid)) return false; - */ return true; } @@ -456,43 +444,26 @@ static bool __esd_check_valid_privilege_by_cynara(const char *appid, const char return has_privilege; } -#if 0 -static int __esd_privilege_func(const char *name, void *user_data) -{ - esd_privilege_check *epc = (esd_privilege_check *)user_data; - - if (strcmp(name, epc->privilege_name) == 0) { - epc->validation = 1; - return -1; - } else { - epc->validation = 0; - return 0; - } -} -#endif - static int __esd_check_app_privileged_event(uid_t uid, const char *appid, const char *pkgid, const char *event_name) { char *privilege_name = NULL; - char client[256] = {0, }; - char *user = NULL; - int retval = 1; + int ret = 0; + int result = 0; _D("event_name(%s), uid(%d), appid(%s), pkgid(%s)", event_name, uid, appid, pkgid); __esd_check_privilege_name(event_name, &privilege_name); if (privilege_name) { - /* TODO(jongmyeong.ko): getting client should be replaced by cynara api */ - snprintf(client, 256, "User::App::%s", pkgid); - user = (char *)g_strdup_printf("%u", uid); - if (!__esd_check_valid_privilege_by_cynara(appid, client, "", user, privilege_name)) { - _E("app(%s) has NOT privilege(%s)", appid, privilege_name); - retval = 0; - } + ret = security_manager_app_has_privilege(appid, privilege_name, uid, &result); + if (ret != SECURITY_MANAGER_SUCCESS) + _E("failed to check privilege(%d)", ret); + _D("result(%d)", result); + } else { + result = 1; } - return retval; + return result; } static void __esd_print_appid_with_eventid(gpointer data, gpointer user_data) @@ -754,28 +725,10 @@ static void __esd_event_launch_with_appid(gpointer data, gpointer user_data) int pid; char event_uri[1024]; bundle *b; - /* char *from_appid = (char *)eep->user_data; */ - /* uid_t from_uid = 0; */ - /* int ret = 0; */ _D("launch_on_event: app_id(%s), event_name(%s)", app_id, eep->event_name); - /* TODO(jongmyeong.ko): for launch by user-event */ - /* - if (from_appid && from_appid[0] != '\0') { - ret = __esd_check_certificate_match(uid, app_id, from_uid, from_appid); - if (ret != ES_R_OK) { - _D("from_appid(%s), no same cert", from_appid); - return; - } - } - */ - - /* FIXME(jongmyeong.ko): aul_app_is_running */ - /* - if (!aul_app_is_running(app_id)) { - */ - if (1) { + if (aul_app_is_running_for_uid(app_id, uid)) { snprintf(event_uri, sizeof(event_uri), "event://%s", eep->event_name); b = bundle_dup(eep->event_data); appsvc_set_operation(b, APPSVC_OPERATION_LAUNCH_ON_EVENT); -- 2.7.4 From 971a9c34d4ea5ae518c9105737ce22d98a9fc9a7 Mon Sep 17 00:00:00 2001 From: Jiwoong Im Date: Mon, 7 Mar 2016 11:59:40 +0900 Subject: [PATCH 10/16] fix return of __get_sender_uid and __get_sender_unixinfo - uid_t(unsigned int) can't be less than zero Change-Id: Ibb66bc32d24221f238dda1d0c6110f1b31d80164 Signed-off-by: Jiwoong Im --- src/esd_main.c | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/src/esd_main.c b/src/esd_main.c index a21fade..1632334 100644 --- a/src/esd_main.c +++ b/src/esd_main.c @@ -178,13 +178,14 @@ static int __esd_check_event_launch_support(const char *event_name) return false; } -static uid_t __get_sender_unixinfo(GDBusConnection *conn, const char *sender_name, const char *type) +static int __get_sender_unixinfo(GDBusConnection *conn, const char *sender_name, const char *type) { GDBusMessage *msg = NULL; GDBusMessage *reply = NULL; GError *err = NULL; GVariant *body; - int value = -1; + int ret = -1; + unsigned int value; msg = g_dbus_message_new_method_call("org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus", type); @@ -207,6 +208,7 @@ static uid_t __get_sender_unixinfo(GDBusConnection *conn, const char *sender_nam body = g_dbus_message_get_body(reply); g_variant_get(body, "(u)", &value); + ret = (int)value; out: if (msg) @@ -214,7 +216,7 @@ out: if (reply) g_object_unref(reply); - return (uid_t)value; + return ret; } static int __get_sender_pid(GDBusConnection *conn, const char *sender_name) @@ -232,13 +234,14 @@ static int __get_sender_pid(GDBusConnection *conn, const char *sender_name) return pid; } -static uid_t __get_sender_uid(GDBusConnection *conn, const char *sender_name) +static int __get_sender_uid(GDBusConnection *conn, const char *sender_name) { - uid_t uid = -1; + int uid = -1; uid = __get_sender_unixinfo(conn, sender_name, "GetConnectionUnixUser"); - if (uid < 0) + if (uid < 0) { _E("failed to get uid"); + } _D("sender_name(%s), uid(%d)", sender_name, uid); @@ -352,7 +355,7 @@ static int __esd_check_trusted_events(GDBusConnection *conn, const char *list_na gchar *str; char tmp_appid[128] = {0, }; int pid = 0; - uid_t uid = 0; + int uid = 0; int ret = 0; result = g_dbus_connection_call_sync(conn, @@ -386,16 +389,16 @@ static int __esd_check_trusted_events(GDBusConnection *conn, const char *list_na _D("uid(%d)", uid); memset(tmp_appid, 0, sizeof(tmp_appid)); - ret = aul_app_get_appid_bypid_for_uid(pid, tmp_appid, sizeof(tmp_appid), uid); + ret = aul_app_get_appid_bypid_for_uid(pid, tmp_appid, sizeof(tmp_appid), (uid_t)uid); if (ret != AUL_R_OK) { _E("failed to get appid by pid(%d)", pid); continue; } _D("appid(%s)", tmp_appid); - if (__esd_check_application_validation(uid, tmp_appid)) { + if (__esd_check_application_validation((uid_t)uid, tmp_appid)) { _D("add to table"); - ret = __esd_trusted_busname_add_item(uid, tmp_appid, (const char *)str, pid); + ret = __esd_trusted_busname_add_item((uid_t)uid, tmp_appid, (const char *)str, pid); if (ret < 0) _E("failed to add item"); } @@ -1199,7 +1202,7 @@ static void check_sender_valid_method_call(GDBusConnection *connection, const gc g_variant_get(parameters, "(is)", &event_sender_pid, &event_name); _D("event_sender_pid(%d), event_name(%s)", event_sender_pid, event_name); - sender_uid = __get_sender_uid(connection, sender); + sender_uid = (uid_t)__get_sender_uid(connection, sender); if (__esd_get_appid_by_pid(event_sender_pid, sender_uid, app_id, sizeof(app_id)) < 0) { result = ES_R_ERROR; } else { @@ -1230,7 +1233,7 @@ static void check_send_event_valid_method_call(GDBusConnection *connection, cons _D("event_name(%s)", event_name); sender_pid = __get_sender_pid(connection, sender); - sender_uid = __get_sender_uid(connection, sender); + sender_uid = (uid_t)__get_sender_uid(connection, sender); if (__esd_get_appid_by_pid(sender_pid, sender_uid, app_id, sizeof(app_id)) < 0) { result = ES_R_ERROR; } else { @@ -1269,7 +1272,7 @@ static void get_trusted_peer_method_call(GDBusConnection *connection, const gcha _D("event_name(%s)", event_name); sender_pid = __get_sender_pid(connection, sender); - sender_uid = __get_sender_uid(connection, sender); + sender_uid = (uid_t)__get_sender_uid(connection, sender); if (__esd_get_appid_by_pid(sender_pid, sender_uid, app_id, sizeof(app_id)) < 0) { result = ES_R_ERROR; } else { @@ -1317,7 +1320,7 @@ static void setup_trusted_peer_method_call(GDBusConnection *connection, const gc if (destination_name && destination_name[0] != '\0') { sender_pid = __get_sender_pid(connection, sender); - sender_uid = __get_sender_uid(connection, sender); + sender_uid = (uid_t)__get_sender_uid(connection, sender); if (__esd_get_appid_by_pid(sender_pid, sender_uid, app_id, sizeof(app_id)) < 0) { result = ES_R_ERROR; } else { @@ -1361,7 +1364,7 @@ static void check_privilege_valid_method_call(GDBusConnection *connection, const if (privilege_name) { sender_pid = __get_sender_pid(connection, sender); - sender_uid = __get_sender_uid(connection, sender); + sender_uid = (uid_t)__get_sender_uid(connection, sender); if (__esd_get_appid_by_pid(sender_pid, sender_uid, app_id, sizeof(app_id)) < 0) { result = ES_R_ERROR; } else { -- 2.7.4 From 13fe83911cd9f9d12eb0826c9e32ac36a77a237a Mon Sep 17 00:00:00 2001 From: jongmyeongko Date: Fri, 11 Mar 2016 16:39:47 +0900 Subject: [PATCH 11/16] fix launch_on_event failure. And, remove gathering appinfo for globalappuser (it's not needed) Change-Id: I9752e8b8b47ea3dc28258b96b7e64f443b74321c Signed-off-by: jongmyeongko --- CMakeLists.txt | 2 +- src/esd_main.c | 21 ++++----------------- 2 files changed, 5 insertions(+), 18 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5d620f0..6d1c5e7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,7 +28,7 @@ ENDFOREACH(flag) ## Additional flag SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden") -SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -g -Wall") +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -g -Wall -Werror") SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}") ## Linker flags diff --git a/src/esd_main.c b/src/esd_main.c index 1632334..9d9af13 100644 --- a/src/esd_main.c +++ b/src/esd_main.c @@ -729,9 +729,10 @@ static void __esd_event_launch_with_appid(gpointer data, gpointer user_data) char event_uri[1024]; bundle *b; - _D("launch_on_event: app_id(%s), event_name(%s)", app_id, eep->event_name); + _D("launch_on_event: app_id(%s), event_name(%s), uid(%d)", + app_id, eep->event_name, uid); - if (aul_app_is_running_for_uid(app_id, uid)) { + if (!aul_app_is_running_for_uid(app_id, uid)) { snprintf(event_uri, sizeof(event_uri), "event://%s", eep->event_name); b = bundle_dup(eep->event_data); appsvc_set_operation(b, APPSVC_OPERATION_LAUNCH_ON_EVENT); @@ -743,7 +744,7 @@ static void __esd_event_launch_with_appid(gpointer data, gpointer user_data) bundle_free(b); } else { - _D("already is running"); + _D("already is running or launch failed"); } } @@ -1529,7 +1530,6 @@ static void __esd_on_name_lost(GDBusConnection *connection, static int __esd_before_loop(void) { int ret = 0; - uid_t uid = 0; GError *error = NULL; guint owner_id = 0; @@ -1656,19 +1656,6 @@ static int __esd_before_loop(void) #endif event_launch_table = g_hash_table_new(g_str_hash, g_str_equal); - - _I("get event launch list"); - - /* get global user info */ - uid = GLOBAL_USER; - ret = pkgmgrinfo_appinfo_get_usr_installed_list(__esd_add_appinfo_handler, uid, &uid); - if (ret < 0) { - _E("failed to get global-app list (%d)", ret); - return ES_R_ERROR; - } - - __esd_launch_table_print_items(); - trusted_busname_table = g_hash_table_new(g_str_hash, g_str_equal); /* gdbus setup for method call */ -- 2.7.4 From ed605f806fc5ab5a5dc118e8fb6e6909f8dae995 Mon Sep 17 00:00:00 2001 From: jongmyeongko Date: Wed, 16 Mar 2016 21:25:10 +0900 Subject: [PATCH 12/16] support new system-event (outgoing msg) Change-Id: Ic423795ff9a39b5eb34bb97662cdb7d30841c103 Signed-off-by: jongmyeongko --- src/esd_main.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/esd_main.c b/src/esd_main.c index 9d9af13..b3c7732 100644 --- a/src/esd_main.c +++ b/src/esd_main.c @@ -30,7 +30,8 @@ static const char *event_launch_support_list[] = { SYS_EVENT_BATTERY_CHARGER_STATUS, SYS_EVENT_USB_STATUS, SYS_EVENT_EARJACK_STATUS, - SYS_EVENT_INCOMMING_MSG + SYS_EVENT_INCOMMING_MSG, + SYS_EVENT_OUTGOING_MSG }; struct privilege_info { @@ -41,7 +42,8 @@ struct privilege_info { static const struct privilege_info privilege_check_list[] = { {SYS_EVENT_DISPLAY_STATE, "http://tizen.org/privilege/display"}, {SYS_EVENT_WIFI_STATE, "http://tizen.org/privilege/network.get"}, - {SYS_EVENT_INCOMMING_MSG, "http://tizen.org/privilege/message.read"} + {SYS_EVENT_INCOMMING_MSG, "http://tizen.org/privilege/message.read"}, + {SYS_EVENT_OUTGOING_MSG, "http://tizen.org/privilege/message.read"} }; static int privilege_check_size = sizeof(privilege_check_list)/sizeof(struct privilege_info); -- 2.7.4 From 7e4d97529e754ad247ac568920793529e2e631e0 Mon Sep 17 00:00:00 2001 From: Jiwoong Im Date: Mon, 14 Mar 2016 20:11:46 +0900 Subject: [PATCH 13/16] check return value of bundle_get_val Change-Id: I4791f876766867ecf6cedf29c899a93fa114ae26 Signed-off-by: Jiwoong Im --- src/esd_main.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/esd_main.c b/src/esd_main.c index b3c7732..f627068 100644 --- a/src/esd_main.c +++ b/src/esd_main.c @@ -779,17 +779,17 @@ static void __esd_launch_event_handler(char *event_name, bundle *data, void *use if (strcmp(SYS_EVENT_BATTERY_CHARGER_STATUS, event_name) == 0) { val = bundle_get_val(data, EVT_KEY_BATTERY_CHARGER_STATUS); _D("charger val(%s)", val); - if (strcmp(EVT_VAL_BATTERY_CHARGER_CONNECTED, val) != 0) + if (val && (strcmp(EVT_VAL_BATTERY_CHARGER_CONNECTED, val) != 0)) return; } else if (strcmp(SYS_EVENT_USB_STATUS, event_name) == 0) { val = bundle_get_val(data, EVT_KEY_USB_STATUS); _D("usb val(%s)", val); - if (strcmp(EVT_VAL_USB_CONNECTED, val) != 0) + if (val && (strcmp(EVT_VAL_USB_CONNECTED, val) != 0)) return; } else if (strcmp(SYS_EVENT_EARJACK_STATUS, event_name) == 0) { val = bundle_get_val(data, EVT_KEY_EARJACK_STATUS); _D("earjack val(%s)", val); - if (strcmp(EVT_VAL_EARJACK_CONNECTED, val) != 0) + if (val && (strcmp(EVT_VAL_EARJACK_CONNECTED, val) != 0)) return; } else if (strcmp(SYS_EVENT_INCOMMING_MSG, event_name) == 0) { msg_type = bundle_get_val(data, EVT_KEY_MSG_TYPE); -- 2.7.4 From 4103413a84971a457eb5cafa7eaef6fbfbc27f0f Mon Sep 17 00:00:00 2001 From: Jiwoong Im Date: Mon, 7 Mar 2016 17:23:38 +0900 Subject: [PATCH 14/16] reduce memroy usage - getting svcapp list by using pkgmgr_info_filter api - fix g_varient_get related leak Change-Id: Iddabaade6efbd16fc8228b083ef5fc9a98e40be1 Signed-off-by: Jiwoong Im --- include/eventsystem_daemon.h | 16 ++++-- src/esd_main.c | 117 ++++++++++++++++++++++++------------------- 2 files changed, 76 insertions(+), 57 deletions(-) diff --git a/include/eventsystem_daemon.h b/include/eventsystem_daemon.h index a06821d..773c315 100644 --- a/include/eventsystem_daemon.h +++ b/include/eventsystem_daemon.h @@ -25,11 +25,6 @@ extern "C" { #endif - -#ifdef __cplusplus -} -#endif - #undef LOG_TAG #define LOG_TAG "ESD" @@ -38,9 +33,20 @@ extern "C" { #define _W(fmt, arg...) LOGW(fmt, ##arg) #define _I(fmt, arg...) LOGI(fmt, ##arg) +#define FREE_AND_NULL(ptr) do { \ + if (ptr) { \ + free((void *)ptr); \ + ptr = NULL; \ + } \ +} while (0) + #define ESD_BOOT_COMPLETED "/tmp/esd_ready" int __esd_register_vconf_callbacks(void); +#ifdef __cplusplus +} +#endif + #endif /* __EVENTSYSTEM_DAEMONE_H__ */ diff --git a/src/esd_main.c b/src/esd_main.c index f627068..89b9ebd 100644 --- a/src/esd_main.c +++ b/src/esd_main.c @@ -935,7 +935,7 @@ static void __esd_filter_name_owner_changed(GDBusConnection *connection, int old_len = 0; int new_len = 0; - g_variant_get(parameters, "(sss)", &name, &old_owner, &new_owner); + g_variant_get(parameters, "(&s&s&s)", &name, &old_owner, &new_owner); if (strstr(name, "event.busname.session")) { old_len = strlen(old_owner); @@ -973,6 +973,7 @@ static int __esd_get_user_items(void) int i = 0; uid_t *uids = NULL; uid_t cur_uid = 0; + pkgmgrinfo_appinfo_filter_h handle = NULL; ret = sd_get_uids(&uids); if (ret < 0) { @@ -989,9 +990,30 @@ static int __esd_get_user_items(void) cur_uid = uids[i]; _I("found uid(%d)", cur_uid); - ret = pkgmgrinfo_appinfo_get_usr_installed_list(__esd_add_appinfo_handler, cur_uid, &cur_uid); - if (ret < 0) - _E("failed to get user(%d)-app list (%d)", cur_uid, ret); + ret = pkgmgrinfo_appinfo_filter_create(&handle); + if (ret < 0) { + _E("failed to create appinfo filter"); + return ES_R_ERROR; + } + ret = pkgmgrinfo_appinfo_filter_add_string(handle, + PMINFO_APPINFO_PROP_APP_COMPONENT, "svcapp"); + if (ret < 0) { + _E("failed to add appinfo filter string"); + return ES_R_ERROR; + } + ret = pkgmgrinfo_appinfo_filter_add_string(handle, + PMINFO_APPINFO_PROP_APP_OPERATION, APPSVC_OPERATION_LAUNCH_ON_EVENT); + if (ret < 0) { + _E("failed to add appinfo filter string"); + return ES_R_ERROR; + } + ret = pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(handle, + __esd_add_appinfo_handler, &cur_uid, cur_uid); + if (ret < 0) { + _E("appinfo filter foreach error"); + return ES_R_ERROR; + } + pkgmgrinfo_appinfo_filter_destroy(handle); } } @@ -1202,7 +1224,7 @@ static void check_sender_valid_method_call(GDBusConnection *connection, const gc int event_sender_pid = 0; uid_t sender_uid = 0; - g_variant_get(parameters, "(is)", &event_sender_pid, &event_name); + g_variant_get(parameters, "(i&s)", &event_sender_pid, &event_name); _D("event_sender_pid(%d), event_name(%s)", event_sender_pid, event_name); sender_uid = (uid_t)__get_sender_uid(connection, sender); @@ -1232,7 +1254,7 @@ static void check_send_event_valid_method_call(GDBusConnection *connection, cons int sender_pid = 0; uid_t sender_uid = 0; - g_variant_get(parameters, "(s)", &event_name); + g_variant_get(parameters, "(&s)", &event_name); _D("event_name(%s)", event_name); sender_pid = __get_sender_pid(connection, sender); @@ -1271,7 +1293,7 @@ static void get_trusted_peer_method_call(GDBusConnection *connection, const gcha char *_busname = NULL; trusted_item *item; - g_variant_get(parameters, "(s)", &event_name); + g_variant_get(parameters, "(&s)", &event_name); _D("event_name(%s)", event_name); sender_pid = __get_sender_pid(connection, sender); @@ -1318,7 +1340,7 @@ static void setup_trusted_peer_method_call(GDBusConnection *connection, const gc uid_t sender_uid = 0; int ret = 0; - g_variant_get(parameters, "(ss)", &event_name, &destination_name); + g_variant_get(parameters, "(&s&s)", &event_name, &destination_name); _D("event_name(%s), destination_name(%s)", event_name, destination_name); if (destination_name && destination_name[0] != '\0') { @@ -1361,7 +1383,7 @@ static void check_privilege_valid_method_call(GDBusConnection *connection, const char *user = NULL; int ret = 0; - g_variant_get(parameters, "(s)", &event_name); + g_variant_get(parameters, "(&s)", &event_name); __esd_check_privilege_name(event_name, &privilege_name); _D("event_name(%s), privilege_name(%s)", event_name, privilege_name); @@ -1422,7 +1444,7 @@ static void get_earlier_data_method_call(GVariant *parameters, GDBusMethodInvoca int len = 0; earlier_item *item; - g_variant_get(parameters, "(s)", &event_name); + g_variant_get(parameters, "(&s)", &event_name); if (event_name && strlen(event_name) > 0) { _D("event_name(%s)", event_name); @@ -1745,7 +1767,6 @@ static int __esd_add_appinfo_handler(const pkgmgrinfo_appinfo_h handle, void *da { char *appid = NULL; char *pkgid = NULL; - pkgmgrinfo_app_component component_type; int ret = 0; uid_t *p_uid = NULL; @@ -1756,65 +1777,57 @@ static int __esd_add_appinfo_handler(const pkgmgrinfo_appinfo_h handle, void *da p_uid = (uid_t *)data; - ret = pkgmgrinfo_appinfo_get_appid(handle, &appid); + ret = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgid); if (ret < 0) { _E("failed to get appid"); return ES_R_ERROR; } - ret = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgid); + ret = pkgmgrinfo_appinfo_get_appid(handle, &appid); if (ret < 0) { - _E("failed to get pkgid"); + _E("failed to get appid"); return ES_R_ERROR; } - ret = pkgmgrinfo_appinfo_get_component(handle, &component_type); - if (ret != PMINFO_R_OK) { - _E("fail to get component type"); - return ES_R_ERROR; - } + esd_appctrl_cb_data *cb_data = calloc(1, sizeof(esd_appctrl_cb_data)); - _D("uid(%d), appid(%s), component_type(%d)", *p_uid, appid, component_type); - if (component_type == PMINFO_SVC_APP) { - esd_appctrl_cb_data *cb_data = calloc(1, sizeof(esd_appctrl_cb_data)); - if (cb_data == NULL) { - _E("memory alloc failed"); - return ES_R_ENOMEM; - } - cb_data->appid = strdup(appid); - if (cb_data->appid == NULL) { - _E("out_of_memory"); - FREE_AND_NULL(cb_data); - return ES_R_ENOMEM; - } - cb_data->pkgid = strdup(pkgid); - if (cb_data->pkgid == NULL) { - _E("out_of_memory"); - FREE_AND_NULL(cb_data->appid); - FREE_AND_NULL(cb_data); - return ES_R_ENOMEM; - } - cb_data->uid = *p_uid; - ret = pkgmgrinfo_appinfo_foreach_appcontrol(handle, - (pkgmgrinfo_app_control_list_cb)__esd_appcontrol_cb, cb_data); - - FREE_AND_NULL(cb_data->pkgid); + if (cb_data == NULL) { + _E("memory alloc failed"); + return ES_R_ENOMEM; + } + cb_data->appid = strdup(appid); + if (cb_data->appid == NULL) { + _E("out_of_memory"); + FREE_AND_NULL(cb_data); + return ES_R_ENOMEM; + } + cb_data->pkgid = strdup(pkgid); + if (cb_data->pkgid == NULL) { + _E("out_of_memory"); FREE_AND_NULL(cb_data->appid); FREE_AND_NULL(cb_data); + return ES_R_ENOMEM; + } + cb_data->uid = *p_uid; - if (ret < 0) { - _E("failed to get appcontrol info"); - return ES_R_ERROR; - } - __esd_launch_table_print_items(); + ret = pkgmgrinfo_appinfo_foreach_appcontrol(handle, + (pkgmgrinfo_app_control_list_cb)__esd_appcontrol_cb, cb_data); + + FREE_AND_NULL(cb_data->pkgid); + FREE_AND_NULL(cb_data->appid); + FREE_AND_NULL(cb_data); + + if (ret < 0) { + _E("failed to get appcontrol info"); + return ES_R_ERROR; } return ES_R_OK; } -static int __esd_pkgmgr_event_callback(uid_t target_uid, int req_id, const char *pkg_type, - const char *pkgid, const char *key, const char *val, - const void *pmsg, void *data) +static int __esd_pkgmgr_event_callback(uid_t target_uid, int req_id, + const char *pkg_type, const char *pkgid, const char *key, + const char *val, const void *pmsg, void *data) { esd_pkgmgr_event *pkg_event = (esd_pkgmgr_event *)data; pkgmgrinfo_pkginfo_h handle = NULL; -- 2.7.4 From 3bed6a84a0b988d8473b7f8f4981dfb164dda7c1 Mon Sep 17 00:00:00 2001 From: Jiwoong Im Date: Fri, 8 Apr 2016 10:40:31 +0900 Subject: [PATCH 15/16] move esd.service to graphical.taget.wants Change-Id: I70676579edef6c9d22553145ccdde6310d6758d3 Signed-off-by: Jiwoong Im --- packaging/esd.spec | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packaging/esd.spec b/packaging/esd.spec index 74fd236..06fb481 100644 --- a/packaging/esd.spec +++ b/packaging/esd.spec @@ -55,9 +55,9 @@ make %{?jobs:-j%jobs} rm -rf %{buildroot} %make_install -mkdir -p %{buildroot}%{_unitdir}/default.target.wants +mkdir -p %{buildroot}%{_unitdir}/graphical.target.wants install -m 0644 %SOURCE1 %{buildroot}%{_unitdir}/esd.service -ln -sf ../esd.service %{buildroot}%{_unitdir}/default.target.wants/esd.service +ln -sf ../esd.service %{buildroot}%{_unitdir}/graphical.target.wants/esd.service mkdir -p %{buildroot}/usr/share/license cp LICENSE %{buildroot}/usr/share/license/%{name} @@ -71,7 +71,7 @@ cp LICENSE %{buildroot}/usr/share/license/%{name} %defattr(-,root,root,-) %{_bindir}/esd %{_unitdir}/esd.service -%{_unitdir}/default.target.wants/esd.service +%{_unitdir}/graphical.target.wants/esd.service /usr/share/license/%{name} %files devel -- 2.7.4 From c05da81c51d3493cfbaad1d5d781faa47ae9cb87 Mon Sep 17 00:00:00 2001 From: jongmyeongko Date: Fri, 19 Feb 2016 11:16:54 +0900 Subject: [PATCH 16/16] change uid from 'root' to 'app_fw' Change-Id: I48ccf659800a64af893b084cf8bb089cfcb5272e Signed-off-by: jongmyeongko --- packaging/esd.service | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packaging/esd.service b/packaging/esd.service index 763da0a..78bda75 100644 --- a/packaging/esd.service +++ b/packaging/esd.service @@ -3,6 +3,8 @@ Description=Start the Event System Daemon After=dbus.service [Service] +User=app_fw +Group=app_fw ExecStart=/usr/bin/esd Restart=always RestartSec=0 -- 2.7.4