add smack label check routine / fix prevent issue / apply coding rules 31/54731/2 accepted/tizen/mobile/20151218.085704 accepted/tizen/tv/20151218.085522 accepted/tizen/wearable/20151218.085717 submit/tizen/20151218.052131
authorHyihong Chae <hh.chae@samsung.com>
Thu, 17 Dec 2015 12:47:59 +0000 (21:47 +0900)
committerHyihong Chae <hh.chae@samsung.com>
Fri, 18 Dec 2015 05:12:31 +0000 (14:12 +0900)
Change-Id: I4c64df81434ef3ebaec7ca5041f3b35b61f42313
Signed-off-by: HyiHong Chae <hh.chae@samsung.com>
packaging/mtp-initiator.spec
src/daemon/include/mtp_daemon.h
src/daemon/mtp_daemon_event.c
src/daemon/mtp_daemon_gdbus_deviceinfo.c
src/daemon/mtp_daemon_gdbus_objectinfo.c
src/daemon/mtp_daemon_gdbus_storageinfo.c

index 7604cbe4f988e0f3719dc82a31b85e54d5172e8d..74942003945c3d126ee9bbe70ff01272c91d2644 100755 (executable)
@@ -1,6 +1,6 @@
 Name:       mtp-initiator
 Summary:    mtp(media transfer protocol) initiator
-Version:    1.3.0
+Version:    1.3.2
 Release:    1
 Group:      Network & Connectivity/Other
 License:    Apache-2.0
index 77467c8ce655402ccd0f2afbde986391c6f7a15a..69389b4697e73c3442a9ad07ff39a1ab994235ad 100755 (executable)
@@ -22,6 +22,7 @@
 #include <stdlib.h>
 #include <stdbool.h>
 #include <sqlite3.h>
+#include <sys/xattr.h>
 
 #include <glib.h>
 #include <gio/gio.h>
index 68e74307c4d512a29b68d3ff633575984d33ffde..998833f93628a2994d3069e7c2187ef9ab1286e7 100755 (executable)
@@ -83,6 +83,25 @@ static int __search_empty_slot(mtp_context *mtp_ctx)
        return -1;
 }
 
+static void __wait_smack_labeling(char *usb_node)
+{
+       int check_count = 0;
+
+       do {
+               char label[256] = {0,};
+               getxattr(usb_node, "security.SMACK64", label, 256);
+
+               MTP_LOGI("check_count: %d, label: %s", check_count, label);
+
+               if (label[0] == NULL)
+                       continue;
+               else if (!strcmp(label, "*"))
+                       break;
+
+               usleep(50*1000); /* 50ms */
+       } while (check_count++ < 50);
+}
+
 static int __parsing_usb_busno(const char *devpath)
 {
        int busno = -1;
@@ -247,12 +266,21 @@ void __usb_host_status_changed_cb(const char *dev_path, int bus_no, usbhost_stat
                LIBMTP_Detect_Raw_Devices(&raw_devices, &num_of_devices);
                for (slot = 0; slot < num_of_devices; slot++) {
                        if (bus_no == raw_devices[slot].bus_location) {
-                               MTP_LOGI("connected bus_no: %d", bus_no);
                                int empty_slot = 0;
+                               char usb_node[256] = {0,};
+
+                               MTP_LOGI("connected bus_no: %d", bus_no);
+
+                               snprintf(usb_node, sizeof(usb_node), "/dev/bus/usb/%03d/%03d",
+                                       raw_devices[slot].bus_location, raw_devices[slot].devnum);
+
+                               MTP_LOGI("usb_node : %s", usb_node);
+
+                               __wait_smack_labeling(usb_node);
 
                                device = LIBMTP_Open_Raw_Device_Uncached(&raw_devices[slot]);
                                if (device == NULL) {
-                                       MTP_LOGE("Unable to open raw device[%d]", slot);
+                                       MTP_LOGE("Unable to open raw device: %d", slot);
                                        continue;
                                }
 
@@ -263,6 +291,8 @@ void __usb_host_status_changed_cb(const char *dev_path, int bus_no, usbhost_stat
                                device_info->model_name = LIBMTP_Get_Modelname(device);
 
                                empty_slot = __search_empty_slot(mtp_ctx);
+                               if (empty_slot < 0)
+                                       continue;
 
                                mtp_ctx->device_list->device_info_list[empty_slot] = device_info;
                                mtp_ctx->device_list->device_num++;
@@ -385,6 +415,14 @@ mtp_error_e __device_list_init(mtp_context *mtp_ctx)
                LIBMTP_mtpdevice_t *device;
                mtp_device_info *device_info;
                int empty_slot;
+               char usb_node[256] = {0,};
+
+               snprintf(usb_node, sizeof(usb_node), "/dev/bus/usb/%03d/%03d",
+                       rawdevices[device_index].bus_location, rawdevices[device_index].devnum);
+
+               MTP_LOGI("usb_node : %s", usb_node);
+
+               __wait_smack_labeling(usb_node);
 
                device = LIBMTP_Open_Raw_Device_Uncached(&rawdevices[device_index]);
                if (device == NULL) {
@@ -405,6 +443,8 @@ mtp_error_e __device_list_init(mtp_context *mtp_ctx)
                MTP_LOGI("Device: %s, Bus: %d", device_info->model_name, device_info->bus_location);
 
                empty_slot = __search_empty_slot(mtp_ctx);
+               if (empty_slot < 0)
+                       continue;
 
                mtp_ctx->device_list->device_info_list[empty_slot] = device_info;
                mtp_ctx->device_list->device_num++;
index a76318794b4123b620f80f0c6d924272ca658194..bc09395fd4318d4a6fd348588cec0c7054ed7aee 100755 (executable)
@@ -24,7 +24,7 @@ static void __deviceinfo_get_manufacturername_thread_func(gpointer user_data)
        /* variable definition */
        mtp_param *param = (mtp_param *)user_data;
        mtp_error_e result = MTP_ERROR_NONE;
-       LIBMTP_mtpdevice_t *device;
+       LIBMTP_mtpdevice_t *device = NULL;
        char *name = NULL;
        mtp_device_info *device_info;
        int device_id;
@@ -68,7 +68,7 @@ static void __deviceinfo_get_modelname_thread_func(gpointer user_data)
        /* variable definition */
        mtp_param *param  = (mtp_param *)user_data;
        mtp_error_e result = MTP_ERROR_NONE;
-       LIBMTP_mtpdevice_t *device;
+       LIBMTP_mtpdevice_t *device = NULL;
        char *name = NULL;
        mtp_device_info *device_info;
        int device_id;
@@ -111,7 +111,7 @@ static void __deviceinfo_get_serialnumber_thread_func(gpointer user_data)
 {
        mtp_param *param = (mtp_param *)user_data;
        mtp_error_e result = MTP_ERROR_NONE;
-       LIBMTP_mtpdevice_t *device;
+       LIBMTP_mtpdevice_t *device = NULL;
        char *number = NULL;
        mtp_device_info *device_info;
        int device_id;
@@ -153,7 +153,7 @@ static void __deviceinfo_get_deviceversion_thread_func(gpointer user_data)
 {
        mtp_param *param = (mtp_param *)user_data;
        mtp_error_e result = MTP_ERROR_NONE;
-       LIBMTP_mtpdevice_t *device;
+       LIBMTP_mtpdevice_t *device = NULL;
        char *version = NULL;
        mtp_device_info *device_info;
        int device_id;
index dfb2d6d32f79fb9bc6f28820e29451e11fa5f028..be59861aff96c87a3d2212a32cfe3905771b0d4b 100755 (executable)
@@ -23,13 +23,13 @@ static void __objectinfo_get_property_thread_func(gpointer user_data)
 {
        mtp_param *param = (mtp_param *)user_data;
        mtp_error_e result = MTP_ERROR_NONE;
-       LIBMTP_mtpdevice_t *device_handle;
-       mtp_device_info *device_info;
+       LIBMTP_mtpdevice_t *device_handle = NULL;
+       mtp_device_info *device_info = NULL;
        int device_id;
        int object_handle;
        mtp_property_e property;
        int property_value = 0;
-       MTPObjectInfo *object_info;
+       MTPObjectInfo *object_info = NULL;
 
        g_assert(param != NULL);
        g_assert(param->object != NULL);
@@ -135,13 +135,13 @@ static void __objectinfo_get_property_string_thread_func(gpointer user_data)
 {
        mtp_param *param = (mtp_param *)user_data;
        mtp_error_e result = MTP_ERROR_NONE;
-       LIBMTP_mtpdevice_t *device_handle;
-       mtp_device_info *device_info;
+       LIBMTP_mtpdevice_t *device_handle = NULL;
+       mtp_device_info *device_info = NULL;
        int device_id;
        int object_handle;
        mtp_property_e property;
        char *property_value = NULL;
-       MTPObjectInfo *object_info;
+       MTPObjectInfo *object_info = NULL;
 
        g_assert(param != NULL);
        g_assert(param->object != NULL);
index 5c9755a3cc381fe3b812bf775b1d8d63c7e51548..218f94a3ac46d662c22fe931c2774147da655959 100755 (executable)
@@ -24,9 +24,9 @@ static void __storageinfo_get_description_thread_func(gpointer user_data)
        mtp_error_e result = MTP_ERROR_NONE;
        int device_id;
        int storage_id;
-       LIBMTP_mtpdevice_t *device;
-       LIBMTP_devicestorage_t *storage;
-       mtp_device_info *device_info;
+       LIBMTP_mtpdevice_t *device = NULL;
+       LIBMTP_devicestorage_t *storage = NULL;
+       mtp_device_info *device_info = NULL;
        char *name = NULL;
 
        g_assert(param != NULL);
@@ -50,14 +50,13 @@ static void __storageinfo_get_description_thread_func(gpointer user_data)
 
                if (storage)
                        name = storage->StorageDescription;
+
+               MTP_LOGI("StorageDescription: %s, storage handle: %p", name, storage);
        } else {
                MTP_LOGE("!!! no MTP device");
-               name = strdup("No Device");
                result = MTP_ERROR_NO_DEVICE;
        }
 
-       MTP_LOGI("StorageDescription: %s, storage handle: %p", name, storage);
-
        mtp_gdbuslib_storageinfo_complete_get_description(param->object,
                param->invocation, name, result);
 
@@ -72,9 +71,9 @@ static void __storageinfo_get_freespace_thread_func(gpointer user_data)
        mtp_error_e result = MTP_ERROR_NONE;
        int device_id;
        int storage_id;
-       LIBMTP_mtpdevice_t *device;
-       LIBMTP_devicestorage_t *storage;
-       mtp_device_info *device_info;
+       LIBMTP_mtpdevice_t *device = NULL;
+       LIBMTP_devicestorage_t *storage = NULL;
+       mtp_device_info *device_info = NULL;
        guint64 value = 0;
 
        g_assert(param != NULL);
@@ -98,13 +97,13 @@ static void __storageinfo_get_freespace_thread_func(gpointer user_data)
 
                if (storage)
                        value = storage->FreeSpaceInBytes;
+
+               MTP_LOGI("FreeSpaceInBytes: %llu, storage handle: %p", value, storage);
        } else {
                MTP_LOGE("!!! no MTP device");
                result = MTP_ERROR_NO_DEVICE;
        }
 
-       MTP_LOGI("FreeSpaceInBytes: %llu, storage handle: %p", value, storage);
-
        mtp_gdbuslib_storageinfo_complete_get_free_space(param->object,
                param->invocation, value, result);
 
@@ -119,9 +118,9 @@ static void __storageinfo_get_maxcapacity_thread_func(gpointer user_data)
        mtp_error_e result = MTP_ERROR_NONE;
        int device_id;
        int storage_id;
-       LIBMTP_mtpdevice_t *device;
-       LIBMTP_devicestorage_t *storage;
-       mtp_device_info *device_info;
+       LIBMTP_mtpdevice_t *device = NULL;
+       LIBMTP_devicestorage_t *storage = NULL;
+       mtp_device_info *device_info = NULL;
        guint64 value = 0;
 
        g_assert(param != NULL);
@@ -145,13 +144,13 @@ static void __storageinfo_get_maxcapacity_thread_func(gpointer user_data)
 
                if (storage)
                        value = storage->MaxCapacity;
+
+               MTP_LOGI("MaxCapacity: %llu, storage handle: %p", value, storage);
        } else {
                MTP_LOGE("!!! no MTP device");
                result = MTP_ERROR_NO_DEVICE;
        }
 
-       MTP_LOGI("MaxCapacity: %llu, storage handle: %p", value, storage);
-
        mtp_gdbuslib_storageinfo_complete_get_max_capacity(param->object,
                param->invocation, value, result);
 
@@ -166,9 +165,9 @@ static void __storageinfo_get_storagetype_thread_func(gpointer user_data)
        mtp_error_e result = MTP_ERROR_NONE;
        int device_id;
        int storage_id;
-       LIBMTP_mtpdevice_t *device;
-       LIBMTP_devicestorage_t *storage;
-       mtp_device_info *device_info;
+       LIBMTP_mtpdevice_t *device = NULL;
+       LIBMTP_devicestorage_t *storage = NULL;
+       mtp_device_info *device_info = NULL;
        int value = 0;
 
        g_assert(param != NULL);
@@ -192,13 +191,13 @@ static void __storageinfo_get_storagetype_thread_func(gpointer user_data)
 
                if (storage)
                        value = storage->StorageType;
+
+               MTP_LOGI("StorageType: %d, storage handle: %p", value, storage);
        } else {
                MTP_LOGE("!!! no MTP device");
                result = MTP_ERROR_NO_DEVICE;
        }
 
-       MTP_LOGI("StorageType: %d, storage handle: %p", value, storage);
-
        mtp_gdbuslib_storageinfo_complete_get_storage_type(param->object,
                param->invocation, value, result);
 
@@ -213,9 +212,9 @@ static void __storageinfo_get_volumeidentifier_thread_func(gpointer user_data)
        mtp_error_e result = MTP_ERROR_NONE;
        int device_id;
        int storage_id;
-       LIBMTP_mtpdevice_t *device;
-       LIBMTP_devicestorage_t *storage;
-       mtp_device_info *device_info;
+       LIBMTP_mtpdevice_t *device = NULL;
+       LIBMTP_devicestorage_t *storage = NULL;
+       mtp_device_info *device_info = NULL;
        char *name = NULL;
 
        g_assert(param != NULL);
@@ -239,14 +238,13 @@ static void __storageinfo_get_volumeidentifier_thread_func(gpointer user_data)
 
                if (storage)
                        name = storage->VolumeIdentifier;
+
+               MTP_LOGI("VolumeIdentifier: %s, storage handle: %p", name, storage);
        } else {
                MTP_LOGE("!!! no MTP device");
-               name = strdup("No Device");
                result = MTP_ERROR_NO_DEVICE;
        }
 
-       MTP_LOGI("VolumeIdentifier: %s, storage handle: %p", name, storage);
-
        mtp_gdbuslib_storageinfo_complete_get_volume_identifier(param->object,
                param->invocation, name, result);