INSTALL(TARGETS ${CORE-SOUND-LIB} DESTINATION ${LIB_INSTALL_DIR} COMPONENT RuntimeLibraries)
##########################################################
+# Define cynara lib
+##########################################################
+
+SET(CYNARA-LIB "email-cynara")
+SET(CYNARA-SRCS
+ ${CMAKE_SOURCE_DIR}/email-core/email-core-cynara.c
+)
+
+INCLUDE_DIRECTORIES(
+ ${CMAKE_SOURCE_DIR}/email-common-use/include
+)
+
+INCLUDE(FindPkgConfig)
+SET(PKG_MODULES cynara-client cynara-creds-socket cynara-session)
+
+pkg_check_modules(cynara_pkgs REQUIRED ${PKG_MODULES})
+
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${cynara_pkgs_CFLAGS}")
+SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed")
+
+ADD_LIBRARY(${CYNARA-LIB} SHARED ${CYNARA-SRCS})
+TARGET_LINK_LIBRARIES(${CYNARA-LIB} ${cynara_pkgs_LDFLAGS} dl)
+SET_TARGET_PROPERTIES(${CYNARA-LIB} PROPERTIES SOVERSION ${VERSION_MAJOR})
+SET_TARGET_PROPERTIES(${CYNARA-LIB} PROPERTIES VERSION ${VERSION})
+
+INSTALL(TARGETS ${CYNARA-LIB} DESTINATION ${LIB_INSTALL_DIR} COMPONENT RuntimeLibraries)
+
+##########################################################
# Define Core lib
##########################################################
INCLUDE(FindPkgConfig)
pkg_check_modules(core_pkgs REQUIRED glib-2.0 drm-client dlog dbus-1 gthread-2.0 uw-imap-toolkit vconf vconf-internal-keys secure-storage openssl accounts-svc mm-player mm-session feedback alarm-service notification libcurl libxml-2.0 cert-svc cert-svc-vcore badge capi-appfw-application icu-i18n libtzplatform-config)
-
-#pkg_check_modules(core_pkgs REQUIRED glib-2.0 drm-client dlog dbus-1 gthread-2.0 uw-imap-toolkit vconf vconf-internal-keys contacts-service2 secure-storage openssl accounts-svc mm-player mm-session feedback alarm-service notification libcurl libxml-2.0 cert-svc cert-svc-vcore badge capi-appfw-application icu-i18n libtzplatform-config)
-
set(EXTRA_CFLAGS "")
FOREACH(flag ${core_pkgs_CFLAGS})
SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
ADD_LIBRARY(${CORE-LIB} SHARED ${CORE-SRCS})
-TARGET_LINK_LIBRARIES(${CORE-LIB} ${core_pkgs_LDFLAGS} ${STORAGE-LIB} ${NETWORK-LIB} ${DEVICE-LIB} ${CORE-SOUND-LIB})
+TARGET_LINK_LIBRARIES(${CORE-LIB} ${core_pkgs_LDFLAGS} ${STORAGE-LIB} ${NETWORK-LIB} ${DEVICE-LIB} ${CORE-SOUND-LIB} ${CYNARA-LIB})
SET_TARGET_PROPERTIES(${CORE-LIB} PROPERTIES SOVERSION ${VERSION_MAJOR})
SET_TARGET_PROPERTIES(${CORE-LIB} PROPERTIES VERSION ${VERSION})
--- /dev/null
+/*
+* email-service
+*
+* Copyright (c) 2015 Samsung Electronics Co., Ltd. All rights reserved.
+*
+* Contact: Sunghyun Kwon <sh0701.kwon@samsung.com>, Minsoo Kim <minnsoo.kim@samsung.com>
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*
+*/
+
+/**
+ *
+ * This file contains functionality related to cynara(privilege)
+ * to interact with email-service.
+ * @file email-core-cynara.c
+ * @author sh0701.kwon@samsung.com
+ * @version 0.1
+ * @brief This file contains functionality to provide cynara support in email-service.
+ */
+
+#include <pthread.h>
+#include <cynara-error.h>
+#include <cynara-client.h>
+#include <cynara-session.h>
+#include <cynara-creds-commons.h>
+
+#include "email-debug-log.h"
+#include "email-utilities.h"
+
+typedef struct _cynara_info_t {
+ cynara *email_cynara;
+ enum cynara_client_creds client_method;
+ enum cynara_user_creds user_method;
+} cynara_info_t;
+
+static cynara_info_t *cynara_info = NULL;
+pthread_mutex_t cynara_mutex = PTHREAD_MUTEX_INITIALIZER;
+
+INTERNAL_FUNC int emcore_init_cynara()
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int ret = CYNARA_API_SUCCESS;
+ int err = EMAIL_ERROR_NONE;
+ char errno_buf[ERRNO_BUF_SIZE] = {0};
+
+ ENTER_CRITICAL_SECTION(cynara_mutex);
+ cynara_info = (cynara_info_t *)em_malloc(sizeof(cynara_info));
+ if (cynara_info == NULL) {
+ EM_DEBUG_EXCEPTION("em_malloc failed");
+ err = EMAIL_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ ret = cynara_initialize(&(cynara_info->email_cynara), NULL);
+ if (ret != CYNARA_API_SUCCESS) {
+ cynara_strerror(ret, errno_buf, ERRNO_BUF_SIZE);
+ EM_DEBUG_EXCEPTION("cynara_initialize failed : [%d], error : [%s]",
+ ret,
+ errno_buf);
+ err = EMAIL_ERROR_NOT_INITIALIZED;
+ goto FINISH_OFF;
+ }
+
+ ret = cynara_creds_get_default_client_method(&(cynara_info->client_method));
+ if (ret != CYNARA_API_SUCCESS) {
+ cynara_strerror(ret, errno_buf, ERRNO_BUF_SIZE);
+ EM_DEBUG_EXCEPTION("cynara_creds_get_default_client_method failed : [%d], error : [%s]",
+ ret,
+ errno_buf);
+ err = EMAIL_ERROR_NOT_INITIALIZED;
+ goto FINISH_OFF;
+ }
+
+ ret = cynara_creds_get_default_user_method(&(cynara_info->user_method));
+ if (ret != CYNARA_API_SUCCESS) {
+ cynara_strerror(ret, errno_buf, ERRNO_BUF_SIZE);
+ EM_DEBUG_EXCEPTION("cynara_creds_get_default_user_method failed : [%d], error : [%s]",
+ ret,
+ errno_buf);
+ err = EMAIL_ERROR_NOT_INITIALIZED;
+ goto FINISH_OFF;
+ }
+
+FINISH_OFF:
+
+ LEAVE_CRITICAL_SECTION(cynara_mutex);
+
+ EM_DEBUG_FUNC_END();
+ return err;
+}
+
+INTERNAL_FUNC void emcore_finish_cynara()
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int ret = CYNARA_API_SUCCESS;
+ char errno_buf[ERRNO_BUF_SIZE] = {0};
+
+ if (cynara_info == NULL) {
+ EM_DEBUG_EXCEPTION("cynara did not initialize");
+ return;
+ }
+
+ ENTER_CRITICAL_SECTION(cynara_mutex);
+ ret = cynara_finish(cynara_info->email_cynara);
+ if (ret != CYNARA_API_SUCCESS) {
+ cynara_strerror(ret, errno_buf, ERRNO_BUF_SIZE);
+ EM_DEBUG_EXCEPTION("cynara_finish failed : [%d], error : [%s]",
+ ret,
+ errno_buf);
+ }
+ EM_SAFE_FREE(cynara_info);
+ LEAVE_CRITICAL_SECTION(cynara_mutex);
+
+ EM_DEBUG_FUNC_END();
+}
+
+INTERNAL_FUNC int emcore_check_privilege(int socket_fd)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int ret = CYNARA_API_SUCCESS;
+ int err = EMAIL_ERROR_NONE;
+ char errno_buf[ERRNO_BUF_SIZE] = {0};
+
+ if (socket_fd < 0) {
+ EM_DEBUG_EXCEPTION("Invalid parameter");
+ err = EMAIL_ERROR_INVALID_PARAM;
+ return err;
+ }
+
+ if (cynara_info->email_cynara == NULL) {
+ err = emcore_init_cynara();
+ if (err != EMAIL_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("emcore_init_cynara failed : [%d]", err);
+ return err;
+ }
+ }
+
+ err = EMAIL_ERROR_PERMISSION_DENIED;
+
+ pid_t client_pid = 0;
+ char *client_uid = NULL;
+ char *client_smack = NULL;
+ char *client_session = NULL;
+
+ ENTER_CRITICAL_SECTION(cynara_mutex);
+
+ ret = cynara_creds_socket_get_client(socket_fd, cynara_info->client_method, &client_smack);
+ if (ret != CYNARA_API_SUCCESS) {
+ cynara_strerror(ret, errno_buf, ERRNO_BUF_SIZE);
+ EM_DEBUG_EXCEPTION("cynara_creds_socket_get_client failed : [%d], error : [%s]",
+ ret,
+ errno_buf);
+ goto FINISH_OFF;
+ }
+
+ ret = cynara_creds_socket_get_user(socket_fd, cynara_info->user_method, &client_uid);
+ if (ret != CYNARA_API_SUCCESS) {
+ cynara_strerror(ret, errno_buf, ERRNO_BUF_SIZE);
+ EM_DEBUG_EXCEPTION("cynara_creds_socket_get_user failed : [%d], error : [%s]",
+ ret,
+ errno_buf);
+ goto FINISH_OFF;
+ }
+
+ ret = cynara_creds_socket_get_pid(socket_fd, &client_pid);
+ if (ret != CYNARA_API_SUCCESS) {
+ cynara_strerror(ret, errno_buf, ERRNO_BUF_SIZE);
+ EM_DEBUG_EXCEPTION("cynara_creds_socket_get_pid failed : [%d], error : [%s]",
+ ret,
+ errno_buf);
+ goto FINISH_OFF;
+ }
+
+ client_session = cynara_session_from_pid(client_pid);
+ if (client_session == NULL) {
+ cynara_strerror(ret, errno_buf, ERRNO_BUF_SIZE);
+ EM_DEBUG_EXCEPTION("cynara_session_from_pid failed error : [%s]",
+ errno_buf);
+ goto FINISH_OFF;
+ }
+
+ ret = cynara_check(cynara_info->email_cynara, client_smack, client_session, client_uid,
+ "http://tizen.org/privilege/email");
+ if (ret != CYNARA_API_ACCESS_ALLOWED) {
+ cynara_strerror(ret, errno_buf, ERRNO_BUF_SIZE);
+ EM_DEBUG_EXCEPTION("cynara_check failed : [%d], error : [%s]",
+ ret,
+ errno_buf);
+ goto FINISH_OFF;
+ }
+
+ err = EMAIL_ERROR_NONE;
+
+FINISH_OFF:
+
+ LEAVE_CRITICAL_SECTION(cynara_mutex);
+
+ EM_SAFE_FREE(client_uid);
+ EM_SAFE_FREE(client_smack);
+ EM_SAFE_FREE(client_session);
+
+ EM_DEBUG_FUNC_END();
+ return err;
+}
--- /dev/null
+/*
+* email-service
+*
+* Copyright (c) 2015 Samsung Electronics Co., Ltd. All rights reserved.
+*
+* Contact: Sunghyun Kwon <sh0701.kwon@samsung.com>, Minsoo Kim <minnsoo.kim@samsung.com>
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*
+*/
+
+/**
+ *
+ * This file contains functionality related to cynara(privilege)
+ * to interact with email-service.
+ * @file email-core-cynara.h
+ * @author sh0701.kwon@samsung.com
+ * @version 0.1
+ * @brief This file contains functionality to provide cynara support in email-service.
+ */
+
+INTERNAL_FUNC int emcore_init_cynara();
+
+INTERNAL_FUNC void emcore_finish_cynara();
+
+INTERNAL_FUNC int emcore_check_privilege(int socket_fd);
#include "email-daemon-emn.h"
#include "email-network.h"
#include "email-device.h"
+#include "email-core-cynara.h"
#include "c-client.h"
extern void *
g_type_init();
+ err = emcore_init_cynara();
+ if (err != EMAIL_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("emcore_init_cynara failed : [%d]", err);
+ goto FINISH_OFF;
+ }
+
emstorage_shm_file_init(SHM_FILE_FOR_DB_LOCK);
#ifdef __FEATURE_USE_SHARED_MUTEX_FOR_GENERATING_MAIL_ID__
EM_DEBUG_EXCEPTION("_emdaemon_unload_email_core failed [%d]", err);
goto FINISH_OFF;
}
-
+
+ /* Finish cynara */
+ emcore_finish_cynara();
+
/* free account reference list */
emcore_free_account_reference();
EM_DEBUG_FUNC_BEGIN();
int err = EMAIL_ERROR_NONE;
int nAPIID = emipc_get_api_id(a_hAPI);
+ int client_fd = emipc_get_response_id(a_hAPI);
+
+ err = emcore_check_privilege(client_fd);
+ if (err != EMAIL_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("emcore_check_privilege failed : [%d]", err);
+
+ if (!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
+ EM_DEBUG_EXCEPTION("emipc_add_paramter failed");
+
+ if (!emipc_execute_stub_api(a_hAPI))
+ EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed");
+
+ return;
+ }
switch(nAPIID) {
case _EMAIL_API_ADD_ACCOUNT:
return api_info->app_id;
}
+EXPORT_API long emipc_get_response_id(HIPC_API api)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ emipc_email_api_info *api_info = (emipc_email_api_info *)api;
+ return api_info->response_id;
+}
+
/* note: there incurs additional cost (malloc & memcpy). */
/* if data is a dynamic variable, please use emipc_dynamic_parameter instead */
EXPORT_API bool emipc_add_parameter(HIPC_API api, EPARAMETER_DIRECTION direction, void *data, int data_length)
static int emipc_check_connected(int fd)
{
EM_DEBUG_FUNC_BEGIN ("fd[%d]", fd);
- int found = (g_list_find (connected_fd, (gpointer)fd))? true : false;
+ int found = (g_list_find(connected_fd, (gpointer)fd)) ? true : false;
EM_DEBUG_FUNC_END ("fd found?? [%d]", found);
return found;
}
} else {
for (i = 0; i < event_num; i++) {
int event_fd = events[i].data.fd;
+ GList *tmp_list = NULL;
if (event_fd == stub_socket) { /* if it is socket connection request */
int cfd = emipc_accept_email_socket (stub_socket);
if (cfd < 0) {
EM_DEBUG_EXCEPTION ("emipc_accept_email_socket failed [%d]", cfd);
- /* EM_DEBUG_CRITICAL_EXCEPTION ("accept failed: %s[%d]", EM_STRERROR(errno_buf), errno);*/
+ continue;
}
ev.events = EPOLLIN;
ev.data.fd = cfd;
if (epoll_ctl(epfd, EPOLL_CTL_ADD, cfd, &ev) == -1) {
EM_DEBUG_EXCEPTION("epoll_ctl failed [%s][%d]", EM_STRERROR(errno_buf), errno);
- /*EM_DEBUG_CRITICAL_EXCEPTION("epoll_ctl failed:%s[%d]", EM_STRERROR(errno_buf), errno);*/
+ close(cfd);
+ continue;
}
+
connected_fd = g_list_prepend (connected_fd, (gpointer)cfd);
} else {
int recv_len;
recv_len = emipc_recv_email_socket(event_fd, &sz_buf);
- if(recv_len > 0) {
+ if (recv_len > 0) {
EM_DEBUG_LOG("[IPCLib]Stub Socket Recv [Socket ID = %d], [recv_len = %d]", event_fd, recv_len);
/* IPC request stream is at least 16byte */
emipc_create_task((unsigned char *)sz_buf, event_fd);
} else
EM_DEBUG_LOG("[IPCLib] Stream size is less than default size");
- } else if( recv_len == 0 ) {
+ } else if (recv_len == 0) {
EM_DEBUG_LOG("[IPCLib] Client closed connection [%d]", event_fd);
if (epoll_ctl(epfd, EPOLL_CTL_DEL, event_fd, events) == -1) {
EM_DEBUG_EXCEPTION("epoll_ctl failed: %s[%d]", EM_STRERROR(errno_buf), errno);
EM_DEBUG_CRITICAL_EXCEPTION("epoll_ctl failed: %s[%d]", EM_STRERROR(errno_buf), errno);
}
- connected_fd = g_list_remove (connected_fd, (gpointer)event_fd);
+
+ connected_fd = g_list_remove(connected_fd, (gpointer)event_fd);
close(event_fd);
}
EM_SAFE_FREE(sz_buf);
/*
* email-service
*
-* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+* Copyright (c) 2012 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
*
* Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com>
*
EM_DEBUG_EXCEPTION("emipc_deserialize_api_info failed");
return false;
}
+
task->api_info->response_id = response_id;
return true;
}
EXPORT_API long emipc_get_api_id(HIPC_API input_api_handle);
EXPORT_API long emipc_get_app_id(HIPC_API input_api_handle);
+EXPORT_API long emipc_get_response_id(HIPC_API input_api_handle);
EXPORT_API bool emipc_add_parameter(HIPC_API api, EPARAMETER_DIRECTION direction, void *data, int data_length);
EXPORT_API bool emipc_add_dynamic_parameter(HIPC_API api, EPARAMETER_DIRECTION direction, void *data, int data_length);
BuildRequires: pkgconfig(libsmack)
BuildRequires: pkgconfig(deviced)
BuildRequires: pkgconfig(icu-i18n)
+BuildRequires: pkgconfig(cynara-client)
+BuildRequires: pkgconfig(cynara-creds-socket)
+BuildRequires: pkgconfig(cynara-session)
+BuildRequires: pkgconfig(cynara-creds-commons)
BuildRequires: pkgconfig(libtzplatform-config)
Requires: libtzplatform-config