mot-agent: fix bugs when MOT failsure occurs after MOT & remove MO
authorsaerome.kim <saerome.kim@samsung.com>
Mon, 15 Jan 2018 08:32:09 +0000 (17:32 +0900)
committersaerome.kim <saerome.kim@samsung.com>
Mon, 2 Jul 2018 10:38:40 +0000 (19:38 +0900)
Even if we remove MO information at remote device, our local
provisioning tool has CRED info for remote device. So in this case, 2nd
trial of MOT always fails due to remained CRED info. for remote device.

- add 'remove_cred_local' & 'remove_cred_local_done' GDBus signal
- To remove MO information:
  1. Call 'remove_mo' <UIID>
  2. Call 'remove_cred_local' <UUID>

Signed-off-by: saerome.kim <saerome.kim@samsung.com>
oic_svr_db_ma.dat [new file with mode: 0644]
src/companion-manager/include/comp_mot_agent.h
src/companion-manager/src/comp_mot_agent.c
src/mot-agent/introspection/ma.xml
src/mot-agent/ma-db.c
src/mot-agent/ma-db.h
src/mot-agent/ma-service-interface.c
src/mot-agent/ma-subowner.c
src/mot-agent/ma-subowner.h

diff --git a/oic_svr_db_ma.dat b/oic_svr_db_ma.dat
new file mode 100644 (file)
index 0000000..14e9ffa
Binary files /dev/null and b/oic_svr_db_ma.dat differ
index abebe8a2a2d094b46914c0ad4f2f13740c407e54..53c498025bb25d896e0c001dc2d97cd053c7f193 100755 (executable)
@@ -33,6 +33,7 @@ int agent_pairwise(char* target1, char *subject1, char *uri1,
        char *rt1, char *interface1, int permission1, char* target2, char *subject2, char *uri2,
        char *rt2, char *interface2, int permission2);
 int agent_remove_mo_at_device(char* uuid_str);
+int agent_remove_cred_at_local(char* uuid_str);
 int agent_remove_myowned_device(char* uuid_str);
 
  #endif /* __COMP_MOT_AGENT_H__ */
\ No newline at end of file
index d1f3cb96e43c122a0fa685a6dd8dde5c2929782b..413004e4a6f249d4722d09e8a31a9f8c9d7c5515 100755 (executable)
@@ -203,6 +203,32 @@ int agent_remove_mo_at_device(char* uuid_str)
        return result;
 }
 
+int agent_remove_cred_at_local(char* uuid_str)
+{
+       GVariant *variant = NULL;
+       int result = COMP_ERROR_NONE;
+       GError *error = NULL;
+
+       if (NULL == agent.dbus_connection || NULL == agent.gproxy_agent_service) {
+               LOG_ERR("I/O error");
+               return COMP_ERROR_IO_ERROR;
+       }
+
+       variant = g_dbus_proxy_call_sync(agent.gproxy_agent_service, "remove_cred_local",
+                       g_variant_new("(s)", uuid_str), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
+       if (variant) {
+               g_variant_get(variant, "(i)", &result);
+               LOGD("remove_cred_cocal status 0x%x", result);
+       } else if (error) {
+               LOGE("Failed DBus call [%s]", error->message);
+               g_error_free(error);
+               return COMP_ERROR_IO_ERROR;
+       }
+
+       return result;
+}
+
+
 int agent_remove_myowned_device(char* uuid_str)
 {
        GVariant *variant = NULL;
@@ -553,6 +579,9 @@ static void _agent_signal_handler(GDBusConnection *connection,
        } else if (0 == g_strcmp0(signal_name, "remove_mo_done")) {
                g_variant_get(parameters, "(i)", &result);
                LOG_DEBUG("Result : %d", result);
+       } else if (0 == g_strcmp0(signal_name, "remove_cred_local_done")) {
+               g_variant_get(parameters, "(i)", &result);
+               LOG_DEBUG("Result : %d", result);
 
                comp_group_notify_group_dismiss(result);
        } else if (0 == g_strcmp0(signal_name, "pairwise_done")) {
@@ -623,6 +652,17 @@ static int _subscribe_event()
        h->dbus_sub_ids = g_list_append(h->dbus_sub_ids, GUINT_TO_POINTER(id));
        LOG_DEBUG("subscribed for (remove_mo_done) signal %d", id);
 
+       /* remove_cred_local_done */
+       id = g_dbus_connection_signal_subscribe(h->dbus_connection, NULL, AGENT_SERVER_NAME,
+                       "remove_cred_local_done", AGENT_OBJECT_PATH, NULL,
+                       G_DBUS_CALL_FLAGS_NONE, _agent_signal_handler, h, NULL);
+       if (0 == id) {
+               LOG_ERR("g_dbus_connection_signal_subscribe(remove_cred_local_done) Fail(%d)", errno);
+               return -1;
+       }
+       h->dbus_sub_ids = g_list_append(h->dbus_sub_ids, GUINT_TO_POINTER(id));
+       LOG_DEBUG("subscribed for (remove_cred_local_done) signal %d", id);
+
        /* acl_done */
        id = g_dbus_connection_signal_subscribe(h->dbus_connection, NULL, AGENT_SERVER_NAME,
                        "acl_done", AGENT_OBJECT_PATH, NULL,
index de168bc837f81455f1bed65e33c4b4857e321e2f..6165439f3d7f3e6d08b7cd16c013f69494bd639d 100644 (file)
             <arg type="s" name="target" direction="in"/>\r
             <arg type="i" name="result" direction="out"/>\r
             </method>\r
+        <method name="remove_cred_local">\r
+            <arg type="s" name="target" direction="in"/>\r
+            <arg type="i" name="result" direction="out"/>\r
+            </method>\r
         <method name="acl">\r
             <arg type="s" name="target" direction="in"/>\r
             <arg type="s" name="subject" direction="in"/>\r
@@ -77,6 +81,9 @@
        <signal name="remove_mo_done">\r
             <arg type="i" name="result" direction="out"/>\r
         </signal>\r
+       <signal name="remove_cred_local_done">\r
+            <arg type="i" name="result" direction="out"/>\r
+        </signal>\r
         <signal name="acl_done">\r
             <arg type="i" name="result" direction="out"/>\r
         </signal>\r
index edf9ff938517cca51b46833faabef421654f0d26..3c12909995d54d1c8672b8f8941ee0b9f643c1b9 100644 (file)
@@ -126,7 +126,7 @@ static OCStackResult rollback()
        return OC_STACK_OK;
 }
 
-int openDB()
+int ma_open_db()
 {
        int result = 0;
        char path[MAX_FILE_PATH_LEN] = {0,};
@@ -142,7 +142,7 @@ int openDB()
        return OC_STACK_OK;
 }
 
-int closeDB()
+int ma_close_db()
 {
        CHECK_PDM_INIT();
        int res = 0;
@@ -235,7 +235,7 @@ static OCStackResult removeFromDeviceList(int id)
        return OC_STACK_OK;
 }
 
-int PDMDeleteDevice(const OicUuid_t *UUID)
+int ma_delete_device(const OicUuid_t *UUID)
 {
        CHECK_PDM_INIT();
        if (NULL == UUID)
@@ -282,7 +282,7 @@ static OCStackResult removeLink(int id1, int id2)
        return OC_STACK_OK;
 }
 
-int PDMUnlinkDevices(const OicUuid_t *UUID1, const OicUuid_t *UUID2)
+int ma_unlink_devices(const OicUuid_t *UUID1, const OicUuid_t *UUID2)
 {
        CHECK_PDM_INIT();
        if (NULL == UUID1 || NULL == UUID2)
index 4eb8a6c3219de9abe90a5d222d51f402bff86a1e..47ef03e2b4a68e795db2788ffe52192de5821c61 100644 (file)
 extern "C" {
 #endif
 
-int openDB();
-int closeDB();
-int PDMDeleteDevice(const OicUuid_t *UUID);
-int PDMUnlinkDevices(const OicUuid_t *UUID1, const OicUuid_t *UUID2);
+int ma_open_db();
+int ma_close_db();
+int ma_delete_device(const OicUuid_t *UUID);
+int ma_unlink_devices(const OicUuid_t *UUID1, const OicUuid_t *UUID2);
 
 #ifdef __cplusplus
 }
index 7e84e09c859b21dda2575748a783e8e98ef8b496..c021b22d5beeffe16c69f73c76ad68f08ca8aeee 100644 (file)
@@ -204,6 +204,23 @@ static gboolean _ma_dbus_handle_remove_mo(NetMa *object,
        return TRUE;\r
 }\r
 \r
+static gboolean _ma_dbus_handle_remove_cred_local(NetMa *object,\r
+               GDBusMethodInvocation *invocation,  gchar *arg_target, gpointer user_data)\r
+{\r
+       int ret = MA_ERROR_NONE;\r
+       ma_service *service = (ma_service *)user_data;\r
+\r
+       ma_check_null_ret_error("service", service, FALSE);\r
+\r
+\r
+       ret = ma_request_remove_cred_local(service, arg_target);\r
+       if (MA_ERROR_NONE != ret)\r
+               MA_LOGE("Failed to ma_request_remove_mo !");\r
+\r
+       net_ma_complete_remove_cred_local(object, invocation, ret);\r
+\r
+       return TRUE;\r
+}\r
 \r
 static gboolean _ma_dbus_handle_acl(NetMa *object,\r
                GDBusMethodInvocation *invocation, gchar *arg_target, gchar *arg_subject, gchar *arg_uri,\r
@@ -329,6 +346,8 @@ static void _ma_dbus_on_bus_acquired(GDBusConnection *conn, const gchar *name,
                        G_CALLBACK(_ma_dbus_handle_mot), service);\r
        g_signal_connect(ma_dbus_object, "handle-remove-mo",\r
                        G_CALLBACK(_ma_dbus_handle_remove_mo), service);\r
+       g_signal_connect(ma_dbus_object, "handle-remove-cred-local",\r
+                       G_CALLBACK(_ma_dbus_handle_remove_cred_local), service);\r
        g_signal_connect(ma_dbus_object, "handle-acl",\r
                        G_CALLBACK(_ma_dbus_handle_acl), service);\r
        g_signal_connect(ma_dbus_object, "handle-cred",\r
index 9c8cdf95790bf4ad2ff4cf7e0bb39f845fb568d5..a7c37c96ba5a6ea529a9fec859076dfd55d5c7d8 100644 (file)
@@ -783,6 +783,9 @@ static gboolean _ma_timeout_cb(gpointer data)
        case MA_REMOVE_MOT:
                net_ma_emit_remove_mo_done(ma_dbus_get_object(), MA_ERROR_OPERATION_FAILED);
                break;
+       case MA_REMOVE_CRED_LOCAL:
+               net_ma_emit_remove_cred_local_done(ma_dbus_get_object(), MA_ERROR_OPERATION_FAILED);
+               break;
        case MA_UNPAIR:
                net_ma_emit_unpair_done(ma_dbus_get_object(), MA_ERROR_OPERATION_FAILED);
                break;
@@ -898,8 +901,10 @@ static int _disc_owned_devs(ma_service *service)
 
 static void _mot_cb(void* ctx, int num, OCProvisionResult_t* arr, bool has_error)
 {
+#if MANIPULATE_LOCAL_PDM
        int i = 0;
        int ret = OC_STACK_OK;
+#endif
        ma_subowner_s *client = (ma_subowner_s *)ctx;
 
        if (!has_error)  {
@@ -908,19 +913,20 @@ static void _mot_cb(void* ctx, int num, OCProvisionResult_t* arr, bool has_error
                MA_LOGD( "Multiple Ownership Transfer FAILED ");
 
                _print_result_list((const OCProvisionResult_t*) arr, num);
-
-               ret = openDB();
+#if MANIPULATE_LOCAL_PDM
+               ret = ma_open_db();
                if (OC_STACK_OK  != ret)
                        MA_LOGE( "openDB: ret = %d (%s)", ret, _error_to_string(ret));
 
                for ( ; num > i; ++i) {
                        if (OC_STACK_OK !=arr[i].res) {
-                               ret = PDMDeleteDevice((const OicUuid_t*) &arr[i].deviceId);
+                               ret = ma_delete_device((const OicUuid_t*) &arr[i].deviceId);
                        }
                }
-               ret = closeDB();
+               ret = ma_close_db();
                if (OC_STACK_OK  != ret)
                        MA_LOGE( "closeDB: ret = %d (%s)", ret, _error_to_string(ret));
+#endif
        }
        client->g_doneCB = true;
 }
@@ -1037,7 +1043,6 @@ static void _remove_mo_cb(void* ctx, int num, OCProvisionResult_t* arr, bool has
                _print_result_list((const OCProvisionResult_t*) arr, num);
        }
        client->g_doneCB = true;
-       OCTerminatePM();
 }
 
 static gpointer _remove_mo_func(gpointer data)
@@ -1068,17 +1073,17 @@ static gpointer _remove_mo_func(gpointer data)
                MA_LOGE("GetDoxmDevOwnerId faild = [%d][%s]", ret, _error_to_string(ret));
                goto MOT_ENDED;
        }
-
-       ret = openDB();
+#if MANIPULATE_LOCAL_PDM
+       ret = ma_open_db();
        if (OC_STACK_OK  != ret)
                MA_LOGE( "openDB: ret = %d (%s)", ret, _error_to_string(ret));
-       ret = PDMDeleteDevice((const OicUuid_t*) uuid_target);
+       ret = ma_delete_device((const OicUuid_t*) uuid_target);
        if (OC_STACK_OK  != ret)
                MA_LOGE( "delete_mowned_device_db: ret = %d (%s)", ret, _error_to_string(ret));
-       ret = closeDB();
+       ret = ma_close_db();
        if (OC_STACK_OK  != ret)
                MA_LOGE( "closeDB: ret = %d (%s)", ret, _error_to_string(ret));
-
+#endif
        ret = OCRemoveSubOwner(g_client, src_dev, &uuid_mowner, _remove_mo_cb);
        if (OC_STACK_OK != ret )  {
                MA_LOGE( "OCRemoveSubOwner: ret = %d (%s)", ret, _error_to_string(ret));
@@ -1134,6 +1139,92 @@ static int _ma_remove_mo(ma_service *service, gchar *uuid_str)
        return MA_ERROR_NONE;
 }
 
+static void _remove_remove_cred_local_cb(void* ctx, int num,
+       OCProvisionResult_t* arr, bool has_error)
+{
+       ma_subowner_s *client = (ma_subowner_s *)ctx;
+
+       if (!has_error)  {
+               MA_LOGD("Remove CRED for mowned device SUCCEEDED");
+       } else {
+               MA_LOGD( "Remove CRED for mowned device  FAILED ");
+               _print_result_list((const OCProvisionResult_t*) arr, num);
+       }
+       client->g_doneCB = true;
+}
+
+static gpointer _remove_cred_local_func(gpointer data)
+{
+       OCStackResult ret = OC_STACK_OK;
+       ma_req_cb_s *con = (ma_req_cb_s *)data;
+
+       OicUuid_t *uuid = NULL;
+
+       if (!con->target_to_revoke) {
+               MA_LOGE("Some parameters are wrong");
+               MA_LOGE("%s", con->target_to_revoke );
+               goto PVACL_ERROR;
+       }
+
+       uuid = _convert_uuid(con->target_to_revoke);
+
+       g_client->g_doneCB = false;
+       MA_LOGI(" Removing CRED for remote device at local SVR DB");
+
+       ret = OCRemoveDeviceWithUuid((void*) g_client, CALLBACK_TIMEOUT_5S,  uuid,
+               _remove_remove_cred_local_cb );
+       if (OC_STACK_OK != ret) {
+               MA_LOGD( "OCRemoveDeviceWithUuid API error: %d (%s)", ret, _error_to_string(ret));
+               goto PVACL_ERROR;
+       }
+
+       ret = _wait_cb_ret(CALLBACK_TIMEOUT_5S);
+       if (ret) {
+               MA_LOGE( "OCRemoveDeviceWithUuid Faild = %d", errno);
+               goto PVACL_ERROR;
+       }
+       /* Disaply result result */
+       MA_LOGI(" Removing CRED info. at local SVR DB - Done");
+
+PVACL_ERROR:
+       /* Notify ACL result  */
+       net_ma_emit_remove_cred_local_done(ma_dbus_get_object(), (int)ret);
+       if (uuid)
+               g_free(uuid);
+       _request_cleanup(con);
+       g_thread_exit(GINT_TO_POINTER (1));
+       return NULL;
+}
+
+static int _ma_remove_cred_local(ma_service *service, gchar *uuid_str)
+{
+       ma_req_cb_s *con = NULL;
+       con = g_malloc0(sizeof(ma_req_cb_s));
+       if (NULL == con) {
+               MA_LOGE( "g_malloc0() Fail=%d", errno);
+               /* Unset d2ds status 'pending' */
+               g_atomic_int_set(&service->pending, 0);
+               return MA_ERROR_OUT_OF_MEMORY;
+       }
+
+       con->userdata = service;
+       con->cid = MA_REMOVE_CRED_LOCAL;
+       con->target_to_revoke = g_strdup(uuid_str);
+
+       con->thread = g_thread_try_new("remove_mowned_dev_cred", _remove_cred_local_func, con, NULL);
+       if (!con->thread) {
+               MA_LOGE("Failed to create thread");
+               _request_cleanup(con);
+               return MA_ERROR_OUT_OF_MEMORY;
+       }
+       g_thread_unref(con->thread);
+
+#ifdef TIMEOUT_USED
+       con->tid = g_timeout_add_seconds(CALLBACK_TIMEOUT_5S + 1, _ma_timeout_cb, con);
+#endif
+       return MA_ERROR_NONE;
+}
+
 #if 0 /* TEST */
 static int sendGetLed()
 {
@@ -1988,6 +2079,31 @@ int ma_request_remove_mo(ma_service *service, gchar* uuid_str)
        return ret;
 }
 
+int ma_request_remove_cred_local(ma_service *service, gchar* uuid_str)
+{
+       int ret =MA_ERROR_NONE;
+
+       ma_check_null_ret_error("service", service, FALSE);
+
+       MA_LOGD("[IPC] Remove CRED for Owned Dev in my SVR DB");
+
+       /* If we are working now? */
+       if (g_atomic_int_get(&service->pending))
+               return MA_ERROR_IN_PROGRESS;
+
+       if (!uuid_str) {
+               MA_LOGE("uuid_str = %s", uuid_str);
+               return MA_ERROR_INVALID_PARAMETER;
+       }
+
+       /* Set d2ds status 'pending' */
+       g_atomic_int_set(&service->pending, 1);
+
+       ret = _ma_remove_cred_local(service, uuid_str);
+
+       return ret;
+}
+
 int ma_request_prov_acl(ma_service *service, gchar *target, gchar *subject,
        gchar *rsrc_uri, gchar *rsrc_type, gchar *rsrc_interface, int permission)
 {
index 0d60c7f176ed1e11c8f2813a0b47a2f31b9e7ccb..3c5c1ac6f5fb1e0917c1de8e35f2a324dafa6ff9 100644 (file)
@@ -33,6 +33,7 @@ typedef enum {
        MA_PROV_ACL, /**< ACL Provisioning */
        MA_PROV_CRED, /**< CRED Provisioning */
        MA_REMOVE_MOT, /**< Remove Multiple Ownership */
+       MA_REMOVE_CRED_LOCAL, /**< Remove CRED my owned device in MOT agent's SVR DB */
        MA_UNPAIR, /**< Unpair */
        MA_PROV_PAIRWISE, /** < Pairwise Provisioning */
 } ma_cmd_id_e;
@@ -52,6 +53,7 @@ int ma_request_disc_mot_enb_devs(ma_service *service);
 int ma_request_disc_owned_devs(ma_service *service);
 int ma_request_mot(ma_service *service, gchar* uuid, gchar *pin);
 int ma_request_remove_mo(ma_service *service, gchar* uuid_str);
+int ma_request_remove_cred_local(ma_service *service, gchar* uuid_str);
 int ma_request_prov_acl(ma_service *service, gchar *target, gchar *subject,
        gchar *rsrc_uri, gchar *rsrc_type, gchar *rsrc_interface, int permission);
 int ma_request_prov_cred(ma_service *service, gchar *uuid_dev1,