From 962149705ee4ff166039cd57bee14454282ba36f Mon Sep 17 00:00:00 2001 From: Jongkyu Koo Date: Tue, 8 Nov 2016 15:12:09 +0900 Subject: [PATCH] add interface with system session Change-Id: Ia98f6736948628f9f4ff7509fa781407b4dd62c5 Signed-off-by: Jongkyu Koo --- client/CMakeLists.txt | 2 +- client/ctsvc_client_ipc.c | 6 +++++- client/ctsvc_client_noti.c | 15 +++++++++++++-- client/ctsvc_client_utils.c | 39 +++++++++++++++++++++++++++++++++++++++ client/ctsvc_client_utils.h | 1 + common/ctsvc_socket.c | 14 ++++++++++++-- packaging/contacts-service.spec | 4 +++- server/CMakeLists.txt | 2 +- server/ctsvc_server.c | 2 +- server/ctsvc_server_socket.c | 5 ++--- server/db/ctsvc_db_schema.h | 2 +- 11 files changed, 79 insertions(+), 13 deletions(-) diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index f07f3a4..6682764 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -102,7 +102,7 @@ SET(SRCS ${SRCS} ENDIF(ENABLE_LOG_FEATURE) pkg_check_modules(client_pkgs REQUIRED glib-2.0 pims-ipc capi-base-common dlog libtzplatform-config - icu-uc capi-media-image-util) + icu-uc capi-media-image-util libsystemd-login) INCLUDE_DIRECTORIES(${client_pkgs_INCLUDE_DIRS}) LINK_DIRECTORIES(${client_pkgs_LIBRARY_DIRS}) diff --git a/client/ctsvc_client_ipc.c b/client/ctsvc_client_ipc.c index 8d78188..c286a11 100644 --- a/client/ctsvc_client_ipc.c +++ b/client/ctsvc_client_ipc.c @@ -91,8 +91,12 @@ bool ctsvc_ipc_is_busy() static int _ctsvc_ipc_create(pims_ipc_h *p_ipc) { char sock_file[CTSVC_PATH_MAX_LEN] = {0}; + uid_t uid = 0; - snprintf(sock_file, sizeof(sock_file), CTSVC_SOCK_PATH"/.%s", getuid(), + if (CONTACTS_ERROR_NONE != ctsvc_client_get_uid(&uid)) + return CONTACTS_ERROR_SYSTEM; + + snprintf(sock_file, sizeof(sock_file), CTSVC_SOCK_PATH"/.%s", uid, CTSVC_IPC_SERVICE); pims_ipc_h ipc = pims_ipc_create(sock_file); if (NULL == ipc) { diff --git a/client/ctsvc_client_noti.c b/client/ctsvc_client_noti.c index f43b317..d23b19b 100644 --- a/client/ctsvc_client_noti.c +++ b/client/ctsvc_client_noti.c @@ -31,6 +31,7 @@ #include "ctsvc_client_ipc.h" #include "ctsvc_client_setting.h" #include "contacts_extension.h" +#include "ctsvc_client_utils.h" typedef struct { contacts_db_change_cb_with_info cb; @@ -121,8 +122,13 @@ int ctsvc_ipc_create_for_change_subscription() if (NULL == __ipc) { char sock_file[CTSVC_PATH_MAX_LEN] = {0}; + uid_t uid = 0; + + if (CONTACTS_ERROR_NONE != ctsvc_client_get_uid(&uid)) + return CONTACTS_ERROR_SYSTEM; + snprintf(sock_file, sizeof(sock_file), CTSVC_SOCK_PATH"/.%s_for_subscribe", - getuid(), CTSVC_IPC_SERVICE); + uid, CTSVC_IPC_SERVICE); __ipc = pims_ipc_create_for_subscribe(sock_file); if (NULL == __ipc) { /* LCOV_EXCL_START */ @@ -149,8 +155,13 @@ int ctsvc_ipc_recover_for_change_subscription() pims_ipc_destroy_for_subscribe(__ipc); char sock_file[CTSVC_PATH_MAX_LEN] = {0}; + uid_t uid = 0; + + if (CONTACTS_ERROR_NONE != ctsvc_client_get_uid(&uid)) + return CONTACTS_ERROR_SYSTEM; + snprintf(sock_file, sizeof(sock_file), CTSVC_SOCK_PATH"/.%s_for_subscribe", - getuid(), CTSVC_IPC_SERVICE); + uid, CTSVC_IPC_SERVICE); __ipc = pims_ipc_create_for_subscribe(sock_file); if (NULL == __ipc) { ERR("pims_ipc_create_for_subscribe() Fail"); diff --git a/client/ctsvc_client_utils.c b/client/ctsvc_client_utils.c index 52cfe54..d065131 100644 --- a/client/ctsvc_client_utils.c +++ b/client/ctsvc_client_utils.c @@ -21,6 +21,11 @@ #include #include #include +#include + +#include "ctsvc_internal.h" + +#define CTSVC_SYSTEM_SLICE "system.slice" inline unsigned int ctsvc_client_get_pid() { @@ -32,3 +37,37 @@ inline unsigned int ctsvc_client_get_tid() return (unsigned int)syscall(SYS_gettid); } +int ctsvc_client_get_uid(uid_t *uid) +{ + RETV_IF(NULL == uid, CONTACTS_ERROR_INVALID_PARAMETER); + + int ret = 0; + uid_t *active_user_list = NULL; + char *slice = NULL; + *uid = getuid(); + + ret = sd_pid_get_slice(getpid(), &slice); + if (0 <= ret && slice) { + if (STRING_EQUAL == strncmp(slice, CTSVC_SYSTEM_SLICE, strlen(CTSVC_SYSTEM_SLICE))) { + ret = sd_get_active_uids(&active_user_list); + /* the number of active users is 1 in tizen3.0 */ + if (1 == ret && active_user_list) { + *uid = active_user_list[0]; + INFO("uid = %d", *uid); + } else { + ERR("sd_get_active_uids() Fail(%d)", ret); + free(active_user_list); + free(slice); + return CONTACTS_ERROR_SYSTEM; + } + free(active_user_list); + } + free(slice); + } else { + ERR("sd_pid_get_slice() Fail(%d)", ret); + } + INFO("getuid() = %d, uid = %d", getuid(), *uid); + + return CONTACTS_ERROR_NONE; +} + diff --git a/client/ctsvc_client_utils.h b/client/ctsvc_client_utils.h index 3c84dc7..28d9603 100644 --- a/client/ctsvc_client_utils.h +++ b/client/ctsvc_client_utils.h @@ -22,6 +22,7 @@ unsigned int ctsvc_client_get_pid(); unsigned int ctsvc_client_get_tid(); +int ctsvc_client_get_uid(uid_t *uid); #endif /* __CTSVC_CLIENT_UTILS_H__ */ diff --git a/common/ctsvc_socket.c b/common/ctsvc_socket.c index c1c9039..593adbe 100644 --- a/common/ctsvc_socket.c +++ b/common/ctsvc_socket.c @@ -26,7 +26,9 @@ #include "ctsvc_socket.h" #include "ctsvc_mutex.h" #include "ctsvc_inotify.h" - +#ifdef _CONTACTS_IPC_CLIENT +#include "ctsvc_client_utils.h" +#endif static int __ctsvc_conn_refcnt = 0; static int __ctsvc_sockfd = -1; @@ -41,8 +43,16 @@ int ctsvc_socket_init(void) } char sock_file[CTSVC_PATH_MAX_LEN] = {0}; - snprintf(sock_file, sizeof(sock_file), CTSVC_SOCK_PATH"/%s", getuid(), CTSVC_SOCKET_FILE); +#ifdef _CONTACTS_IPC_CLIENT + uid_t uid = 0; + if (CONTACTS_ERROR_NONE != ctsvc_client_get_uid(&uid)) + return CONTACTS_ERROR_SYSTEM; + + snprintf(sock_file, sizeof(sock_file), CTSVC_SOCK_PATH"/%s", uid, CTSVC_SOCKET_FILE); +#else + snprintf(sock_file, sizeof(sock_file), CTSVC_SOCK_PATH"/%s", getuid(), CTSVC_SOCKET_FILE); +#endif bzero(&caddr, sizeof(caddr)); caddr.sun_family = AF_UNIX; snprintf(caddr.sun_path, sizeof(caddr.sun_path), "%s", sock_file); diff --git a/packaging/contacts-service.spec b/packaging/contacts-service.spec index 95ce832..8a2bc50 100644 --- a/packaging/contacts-service.spec +++ b/packaging/contacts-service.spec @@ -1,6 +1,6 @@ Name: contacts-service Summary: Contacts Service -Version: 0.13.60 +Version: 0.13.61 Release: 0 Group: Social & Content/Service License: Apache-2.0 @@ -29,6 +29,8 @@ BuildRequires: pkgconfig(cynara-creds-socket) BuildRequires: pkgconfig(capi-system-info) BuildRequires: pkgconfig(icu-uc) BuildRequires: pkgconfig(phonenumber-utils) +BuildRequires: pkgconfig(libsystemd) + Requires(post): /sbin/ldconfig Requires(postun): /sbin/ldconfig diff --git a/server/CMakeLists.txt b/server/CMakeLists.txt index f476f01..144ffe2 100644 --- a/server/CMakeLists.txt +++ b/server/CMakeLists.txt @@ -159,7 +159,7 @@ ENDIF(ENABLE_LOG_FEATURE) pkg_check_modules(daemon_pkgs REQUIRED glib-2.0 pims-ipc sqlite3 tapi capi-media-image-util accounts-svc libexif libsmack cynara-client cynara-session cynara-creds-socket capi-system-info - phonenumber-utils vconf db-util libtzplatform-config icu-uc) + phonenumber-utils vconf db-util libtzplatform-config icu-uc libsystemd-login) INCLUDE_DIRECTORIES(${daemon_pkgs_INCLUDE_DIRS}) LINK_DIRECTORIES(${daemon_pkgs_LIBRARY_DIRS}) diff --git a/server/ctsvc_server.c b/server/ctsvc_server.c index d9a8471..d180af2 100644 --- a/server/ctsvc_server.c +++ b/server/ctsvc_server.c @@ -242,7 +242,7 @@ static int __server_main(void) snprintf(sock_file, sizeof(sock_file), CTSVC_SOCK_PATH"/.%s_for_subscribe", getuid(), CTSVC_IPC_SERVICE); - pims_ipc_svc_init_for_publish(sock_file, CTS_SECURITY_FILE_GROUP, 0660); + pims_ipc_svc_init_for_publish(sock_file, CTS_SECURITY_FILE_GROUP, CTS_SECURITY_DEFAULT_PERMISSION); ctsvc_noti_publish_socket_initialize(); ret = ctsvc_connect(); diff --git a/server/ctsvc_server_socket.c b/server/ctsvc_server_socket.c index 58adbd5..51ab63e 100644 --- a/server/ctsvc_server_socket.c +++ b/server/ctsvc_server_socket.c @@ -450,9 +450,8 @@ static int _ctsvc_server_create_client_info(int fd, struct client_info **p_info) info->client_session = cynara_session_from_pid(pid); if (NULL == info->client_session) { /* LCOV_EXCL_START */ - ERR("cynara_session_from_pid() return NULL"); - _ctsvc_server_destroy_client_info(info); - return CONTACTS_ERROR_SYSTEM; + WARN("cynara_session_from_pid() return NULL"); + info->client_session = strdup(""); /* LCOV_EXCL_STOP */ } *p_info = info; diff --git a/server/db/ctsvc_db_schema.h b/server/db/ctsvc_db_schema.h index 642e8ad..00d14e6 100644 --- a/server/db/ctsvc_db_schema.h +++ b/server/db/ctsvc_db_schema.h @@ -25,7 +25,7 @@ /* For Security */ #define CTS_SECURITY_FILE_GROUP 5000 -#define CTS_SECURITY_DEFAULT_PERMISSION 0660 +#define CTS_SECURITY_DEFAULT_PERMISSION 0666 #define CTS_SECURITY_DIR_DEFAULT_PERMISSION 0770 #define CTS_SCHEMA_TABLE_TOTAL 10 -- 2.7.4