add permission check in add_changed_cb, get_last_version 88/70888/5 accepted/tizen/common/20160524.150422 accepted/tizen/ivi/20160524.094822 accepted/tizen/mobile/20160524.094719 submit/tizen/20160524.011323
authorJeesun Kim <iamjs.kim@samsung.com>
Mon, 23 May 2016 07:09:02 +0000 (16:09 +0900)
committerJongkyu Koo <jk.koo@samsung.com>
Mon, 23 May 2016 23:48:18 +0000 (16:48 -0700)
Change-Id: I6d39ce6b5673bf05cdce765365555e2a45aea9d7

client/cal_client_db.c
client/cal_client_dbus.c
client/cal_client_dbus.h
common/dbus/cal_dbus.xml
packaging/calendar-service.conf.in
server/cal_server_dbus.c

index 654b630..a5711bd 100644 (file)
@@ -275,7 +275,7 @@ API int calendar_db_add_changed_cb(const char* view_uri, calendar_db_changed_cb
 
        ret = cal_client_handle_get_p(&handle);
        RETVM_IF(CALENDAR_ERROR_NONE != ret, ret, "cal_client_handle_get_p() Fail(%d)", ret);
-       return cal_client_db_add_changed_cb(handle, view_uri, callback, user_data);
+       return cal_dbus_add_changed_cb(handle, view_uri, callback, user_data);
 }
 
 API int calendar_db_remove_changed_cb(const char* view_uri, calendar_db_changed_cb callback, void* user_data)
@@ -288,7 +288,7 @@ API int calendar_db_remove_changed_cb(const char* view_uri, calendar_db_changed_
 
        ret = cal_client_handle_get_p(&handle);
        RETVM_IF(CALENDAR_ERROR_NONE != ret, ret, "cal_client_handle_get_p() Fail(%d)", ret);
-       return cal_client_db_remove_changed_cb(handle, view_uri, callback, user_data);
+       return cal_dbus_remove_changed_cb(handle, view_uri, callback, user_data);
 }
 
 API int calendar_db_insert_vcalendars(const char* vcalendar_stream, int **record_id_array, int *count)
index 6c15b20..5d7d556 100644 (file)
@@ -31,6 +31,7 @@
 #include "cal_list.h"
 #include "cal_client_handle.h"
 #include "cal_client_reminder.h"
+#include "cal_client_db_helper.h"
 
 #define __CAL_CLIENT_ACCESS_MAX 10
 #define __CAL_CLIENT_ALLOW_USEC 25000
@@ -679,6 +680,51 @@ int cal_dbus_get_count_with_query(calendar_h handle, calendar_query_h query, int
        return ret;
 }
 
+int cal_dbus_add_changed_cb(calendar_h handle, const char* view_uri,
+               void *callback, void* user_data)
+{
+       GError *error = NULL;
+       int ret = 0;
+
+       RETV_IF(NULL == handle, CALENDAR_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == callback, CALENDAR_ERROR_INVALID_PARAMETER);
+
+       cal_dbus_call_check_permission_write_sync(cal_dbus_object, NULL, &error);
+       if (error) {
+               ERR("cal_dbus_call_check_permission_write_sync() Fail[%s]", error->message);
+               if (G_DBUS_ERROR_ACCESS_DENIED == error->code)
+                       ret = CALENDAR_ERROR_PERMISSION_DENIED;
+               else
+                       ret = CALENDAR_ERROR_IPC;
+               g_error_free(error);
+               return ret;
+       }
+
+       return cal_client_db_add_changed_cb(handle, view_uri, callback, user_data);
+}
+
+int cal_dbus_remove_changed_cb(calendar_h handle, const char* view_uri,
+               void *callback, void* user_data)
+{
+       GError *error = NULL;
+       int ret = 0;
+
+       RETV_IF(NULL == handle, CALENDAR_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == callback, CALENDAR_ERROR_INVALID_PARAMETER);
+
+       cal_dbus_call_check_permission_write_sync(cal_dbus_object, NULL, &error);
+       if (error) {
+               ERR("cal_dbus_call_check_permission_write_sync() Fail[%s]", error->message);
+               if (G_DBUS_ERROR_ACCESS_DENIED == error->code)
+                       ret = CALENDAR_ERROR_PERMISSION_DENIED;
+               else
+                       ret = CALENDAR_ERROR_IPC;
+               g_error_free(error);
+               return ret;
+       }
+       return cal_client_db_remove_changed_cb(handle, view_uri, callback, user_data);
+}
+
 int cal_dbus_get_current_version(calendar_h handle, int *out_version)
 {
        GError *error = NULL;
@@ -714,9 +760,22 @@ int cal_dbus_get_current_version(calendar_h handle, int *out_version)
 
 int cal_dbus_get_last_change_version(calendar_h handle, int *out_version)
 {
+       GError *error = NULL;
+       int ret = 0;
+
        RETV_IF(NULL == handle, CALENDAR_ERROR_INVALID_PARAMETER);
        RETV_IF(NULL == out_version, CALENDAR_ERROR_INVALID_PARAMETER);
 
+       cal_dbus_call_check_permission_read_sync(cal_dbus_object, NULL, &error);
+       if (error) {
+               ERR("cal_dbus_call_check_permission_read_sync() Fail[%s]", error->message);
+               if (G_DBUS_ERROR_ACCESS_DENIED == error->code)
+                       ret = CALENDAR_ERROR_PERMISSION_DENIED;
+               else
+                       ret = CALENDAR_ERROR_IPC;
+               g_error_free(error);
+               return ret;
+       }
        return cal_handle_get_version(handle, out_version);
 }
 
index 3703f03..ecc04bd 100644 (file)
@@ -56,16 +56,20 @@ int cal_dbus_get_records_with_query(calendar_h handle, calendar_query_h query,
 int cal_dbus_get_count(calendar_h handle, const char *view_uri, int *out_count);
 int cal_dbus_get_count_with_query(calendar_h handle, calendar_query_h query,
                int *out_count);
+int cal_dbus_add_changed_cb(calendar_h handle, const char* view_uri,
+               void *callback, void* user_data);
+int cal_dbus_remove_changed_cb(calendar_h handle, const char* view_uri,
+               void *callback, void* user_data);
 int cal_dbus_get_current_version(calendar_h handle, int *out_version);
 int cal_dbus_get_changes_by_version(calendar_h handle, const char *view_uri,
                int book_id, int version, calendar_list_h *out_list, int *out_version);
 int cal_dbus_get_changes_exception_by_version(calendar_h handle, const char *view_uri,
                int original_id, int version, calendar_list_h *out_list);
+int cal_dbus_get_last_change_version(calendar_h handle, int *out_version);
 int cal_dbus_clean_after_sync(calendar_h handle, int book_id, int version);
 int cal_dbus_insert_vcalendars(calendar_h handle, const char *stream, int **out_ids,
                int *out_count);
 int cal_dbus_replace_vcalendars(calendar_h handle, const char *stream, int *ids,
                int count);
-int cal_dbus_get_last_change_version(calendar_h handle, int *out_version);
 
 #endif /* __CAL_CLIENT_DBUS_H__ */
index 36ac002..b83a7ad 100644 (file)
@@ -1,5 +1,9 @@
 <node>
        <interface name="org.tizen.CalendarService.dbus">
+               <method name="check_permission_read">
+               </method>
+               <method name="check_permission_write">
+               </method>
                <method name="register_resource">
                        <arg type="i" name="ret" direction="out"/>
                </method>
                        <arg type="i" name="version" direction="out"/>
                        <arg type="i" name="ret" direction="out"/>
                </method>
-               <method name="add_changed_cb">
-               </method>
-               <method name="remove_changed_cb">
-               </method>
                <method name="get_changes_by_version">
                        <arg type="(ii)" name="handle" direction="in"/>
                        <arg type="s" name="view_uri" direction="in"/>
                        <arg type="i" name="version" direction="out"/>
                        <arg type="i" name="ret" direction="out"/>
                </method>
-               <method name="get_last_change_version">
-               </method>
                <method name="get_changes_exception_by_version">
                        <arg type="(ii)" name="handle" direction="in"/>
                        <arg type="s" name="view_uri" direction="in"/>
index 6839765..a7e7bd2 100644 (file)
     <policy context="default">
         <allow send_destination="@DBUS_INTERFACE@"/>
                <check send_destination="@DBUS_INTERFACE@"
+                               send_interface="@DBUS_INTERFACE@" send_member="check_permission_write"
+                               privilege="http://tizen.org/privilege/calendar.write"/>
+               <check send_destination="@DBUS_INTERFACE@"
+                               send_interface="@DBUS_INTERFACE@" send_member="check_permission_read"
+                               privilege="http://tizen.org/privilege/calendar.read"/>
+               <check send_destination="@DBUS_INTERFACE@"
                                send_interface="@DBUS_INTERFACE@" send_member="insert_record"
                                privilege="http://tizen.org/privilege/calendar.write"/>
                <check send_destination="@DBUS_INTERFACE@"
@@ -60,9 +66,6 @@
                                send_interface="@DBUS_INTERFACE@" send_member="get_changes_by_version"
                                privilege="http://tizen.org/privilege/calendar.read"/>
                <check send_destination="@DBUS_INTERFACE@"
-                               send_interface="@DBUS_INTERFACE@" send_member="get_last_change_version"
-                               privilege="http://tizen.org/privilege/calendar.read"/>
-               <check send_destination="@DBUS_INTERFACE@"
                                send_interface="@DBUS_INTERFACE@" send_member="get_changes_exception_by_version"
                                privilege="http://tizen.org/privilege/calendar.read"/>
                <check send_destination="@DBUS_INTERFACE@"
index 727fc7d..7d7ec86 100644 (file)
@@ -406,6 +406,18 @@ static gboolean _handle_get_current_version(calDbus *object, GDBusMethodInvocati
        return TRUE;
 }
 
+static gboolean _handle_check_permission_write(calDbus *object, GDBusMethodInvocation *invocation)
+{
+       cal_server_ondemand_start();
+       return TRUE;
+}
+
+static gboolean _handle_check_permission_read(calDbus *object, GDBusMethodInvocation *invocation)
+{
+       cal_server_ondemand_start();
+       return TRUE;
+}
+
 static gboolean _handle_get_changes_by_version(calDbus *object, GDBusMethodInvocation *invocation,
                GVariant *arg_handle, char *view_uri, int book_id, int in_version)
 {
@@ -645,18 +657,12 @@ static void _dbus_on_bus_acquired(GDBusConnection *conn, const gchar *name, gpoi
                        G_CALLBACK(_handle_get_count_with_query), NULL);
        g_signal_connect(dbus_object, "handle-get-current-version",
                        G_CALLBACK(_handle_get_current_version), NULL);
-/*
-       g_signal_connect(dbus_object, "handle-add-changed-cb",
-       G_CALLBACK(_handle_add_changed_cb), NULL);
-       g_signal_connect(dbus_object, "handle-remove-changed-cb",
-       G_CALLBACK(_handle_remove_changed_cb), NULL);
-*/
+       g_signal_connect(dbus_object, "handle-check-permission-write",
+                       G_CALLBACK(_handle_check_permission_write), NULL);
+       g_signal_connect(dbus_object, "handle-check-permission-read",
+                       G_CALLBACK(_handle_check_permission_read), NULL);
        g_signal_connect(dbus_object, "handle-get-changes-by-version",
                        G_CALLBACK(_handle_get_changes_by_version), NULL);
-/*
-       g_signal_connect(dbus_object, "handle-get-last-change-version",
-       G_CALLBACK(_handle_get_last_change_version), NULL);
-*/
        g_signal_connect(dbus_object, "handle-get-changes-exception-by-version",
                        G_CALLBACK(_handle_get_changes_exception_by_version), NULL);
        g_signal_connect(dbus_object, "handle-clean-after-sync",