esd 3.0 migration (multi-user feature, dbus-policy) 54/52854/10 accepted/tizen/mobile/20151207.122101 accepted/tizen/tv/20151207.122118 accepted/tizen/wearable/20151207.122141 submit/tizen/20151206.235943
authorjongmyeongko <jongmyeong.ko@samsung.com>
Thu, 26 Nov 2015 15:46:58 +0000 (00:46 +0900)
committerjongmyeongko <jongmyeong.ko@samsung.com>
Fri, 4 Dec 2015 06:32:01 +0000 (15:32 +0900)
Temporarily, I will keep esd as root-daemon and check full behaviors.

Change-Id: I674091b45187be46872bd74a1f4591ec2c166b06
Signed-off-by: jongmyeongko <jongmyeong.ko@samsung.com>
CMakeLists.txt
eventsystem.conf
packaging/esd.spec
src/esd_main.c

index 06a859c..0208eef 100644 (file)
@@ -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}")
index 994653b..2773b2f 100644 (file)
@@ -4,6 +4,8 @@
 
 <busconfig>
        <policy context="default">
+               <allow own_prefix="event.busname.system"/>
+               <allow own_prefix="event.busname.session"/>
                <deny send_destination="*" send_interface="tizen.system.event" send_type="signal" />
                <allow send_destination="tizen.system.event.app2esd" send_interface="tizen.system.event.app2esd" send_type="method_call" />
        </policy>
index 2d2300f..a84789f 100644 (file)
@@ -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
index 5486111..2093cf5 100644 (file)
 #include <bundle_internal.h>
 #include <fcntl.h>
 #include <vconf.h>
+#include <tzplatform_config.h>
+#include <systemd/sd-login.h>
+#include <cynara-client.h>
+#include <cynara-creds-gdbus.h>
+#include <cynara-session.h>
 #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[] =
 "      </interface>"
 "</node>";
 
-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");
 }