Allow daemon to remove address book 68/146968/7
authorJongkyu Koo <jk.koo@samsung.com>
Thu, 31 Aug 2017 09:40:48 +0000 (18:40 +0900)
committerJongkyu Koo <jk.koo@samsung.com>
Fri, 8 Sep 2017 00:04:31 +0000 (00:04 +0000)
Change-Id: I14e75b413908c30bd945b989685a68e3ecc6ae5f
Signed-off-by: Jongkyu Koo <jk.koo@samsung.com>
packaging/contacts-service.spec
server/db/ctsvc_db_access_control.c

index aec3b30..7f16df3 100644 (file)
@@ -1,6 +1,6 @@
 Name:       contacts-service
 Summary:    Contacts Service
-Version:    0.13.72
+Version:    0.13.73
 Release:    0
 Group:      Social & Content/Service
 License:    Apache-2.0
index 7fd0016..05f2d5c 100644 (file)
@@ -104,6 +104,23 @@ int ctsvc_have_file_read_permission(const char *path)
        return CONTACTS_ERROR_NONE;
 }
 
+static bool __ctsvc_is_allowed_client(const char *client_label, const char *addressbook_label)
+{
+       const char *device_addressbook = "org.tizen.contacts";
+       const char *preload_contacts = "User::Pkg::org.tizen.contacts";
+       const char *user_daemon = "User";
+       const char *system_daemon = "System";
+
+       if (STRING_EQUAL == strncmp(client_label, preload_contacts, strlen(preload_contacts))
+               && STRING_EQUAL == strcmp(addressbook_label, device_addressbook)) /*preload contacts && device addressbook*/
+               return true;
+       else if ((STRING_EQUAL == strcmp(client_label, user_daemon) || STRING_EQUAL == strcmp(client_label, system_daemon))
+               && STRING_EQUAL != strcmp(addressbook_label, device_addressbook)) /*daemon && !device addressbook*/
+               return true;
+
+       return false;
+}
+
 /* this function is called in mutex lock */
 static void __ctsvc_set_permission_info(ctsvc_permission_info_s *info)
 {
@@ -177,7 +194,8 @@ static void __ctsvc_set_permission_info(ctsvc_permission_info_s *info)
                } else if (NULL == info->ipc) { /* contacts-service daemon */
                        wi->id = id;
                        wi->type = CTSVC_TYPE_PERMISSION;
-               } else if (info->smack && temp && STRING_EQUAL == strcmp(temp, info->smack)) { /* owner */
+               } else if (info->smack && temp &&
+                       ((STRING_EQUAL == strcmp(temp, info->smack)) || __ctsvc_is_allowed_client(info->smack, temp))) { /* owner || allow client*/
                        wi->id = id;
                        wi->type = CTSVC_TYPE_PERMISSION;
                } else if (CONTACTS_ADDRESS_BOOK_MODE_NONE == mode) {
@@ -477,9 +495,12 @@ int ctsvc_is_owner(int addressbook_id)
        saved_smack = ctsvc_stmt_get_text(stmt, 1);
        smack = ctsvc_get_client_smack_label();
 
-       if (smack && saved_smack && STRING_EQUAL == strcmp(smack, saved_smack))
-               ret = CONTACTS_ERROR_NONE;
-
+       if (smack && saved_smack) {
+               if (STRING_EQUAL == strcmp(smack, saved_smack)) /*owner*/
+                       ret = CONTACTS_ERROR_NONE;
+               else if (__ctsvc_is_allowed_client(smack, saved_smack))
+                       ret = CONTACTS_ERROR_NONE;
+       }
        ctsvc_stmt_finalize(stmt);
 
        free(smack);