Change daemon user owner to network_fw 33/139333/5 accepted/tizen/4.0/unified/20170816.010639 accepted/tizen/4.0/unified/20170816.014343 accepted/tizen/unified/20170804.025622 submit/tizen/20170803.065852 submit/tizen_4.0/20170811.094300 submit/tizen_4.0/20170814.115522 submit/tizen_4.0_unified/20170814.115522
authorjh8801.jung <jh8801.jung@samsung.com>
Tue, 18 Jul 2017 11:02:24 +0000 (20:02 +0900)
committerjh8801.jung <jh8801.jung@samsung.com>
Thu, 3 Aug 2017 05:06:41 +0000 (14:06 +0900)
Signed-off-by: jh8801.jung <jh8801.jung@samsung.com>
Change-Id: I6306fc3b24cb4824251248c7f09b806a894a6faf

CMakeLists.txt
include/mtp_config.h
include/util/mtp_util.h
mtp-responder.service
packaging/mtp-responder.spec
src/mtp_cmd_handler_util.c
src/mtp_event_handler.c
src/mtp_init.c
src/util/mtp_util.c

index 5dc968a..4e39cfd 100755 (executable)
@@ -13,7 +13,7 @@ AUX_SOURCE_DIRECTORY(${CMAKE_SOURCE_DIR}/src/util SRCS)
 
 INCLUDE(FindPkgConfig)
 pkg_check_modules(pkgs REQUIRED glib-2.0 capi-content-media-content
-       capi-media-metadata-extractor vconf dlog tapi capi-system-info storage)
+       capi-media-metadata-extractor vconf dlog tapi capi-system-info storage libsystemd-daemon)
 
 FOREACH(flag ${pkgs_CFLAGS})
        SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
index d7052a9..eac1d2e 100755 (executable)
@@ -77,7 +77,7 @@
  * Transport related configuration
  */
 /* Internal Storage */
-#define MTP_STORE_PATH_CHAR            "/opt/home/owner/content"
+#define MTP_INTERNAL_PATH_CHAR         "/opt/usr/home/"
 
 /* External Storage */
 #define MTP_EXTERNAL_PATH_CHAR "/opt/media/SDCardA1"
@@ -87,7 +87,7 @@
 #define MTP_FILES_MODIFIED_FILES       "/tmp/mtp_mod_files.log"
 
 /* Base MTP USER Directory */
-#define MTP_USER_DIRECTORY             "/opt/usr/media/user"
+#define MTP_USER_DIRECTORY             "/opt/usr/home/owner/media"
 
 /* Hidden Root directory */
 #define MTP_HIDDEN_PHONE               ".HiddenPhone"
index b0c7bb2..c5d56fd 100755 (executable)
@@ -25,6 +25,7 @@
 #define LOG_TAG "MTP-RESPONDER"
 #endif /* LOG_TAG */
 #include <dlog.h>
+#include <media_content.h>
 
 #define FIND_CMD_LEN                           300
 #define FIND_CMD       "/usr/bin/find %s \\( -iname '*.jpg' -o -iname '*.gif' " \
@@ -148,4 +149,8 @@ phone_status_t _util_get_local_lock_status(void);
 void _util_set_local_lock_status(const phone_status_t val);
 void _util_get_external_path(char *external_path);
 void _util_get_internal_path(char *internal_path);
+mtp_bool _util_media_content_connect();
+void _util_media_content_disconnect();
+
+
 #endif /* _MTP_UTIL_H_ */
index 8941a90..2019999 100755 (executable)
@@ -2,9 +2,8 @@
 Description=MTP responder
 
 [Service]
-User=owner
-Group=users
-SmackProcessLabel=System
+User=network_fw
+Group=network_fw
 SupplementaryGroups=priv_mediastorage priv_externalstorage
 Type=simple
 ExecStart=/usr/bin/mtp-responder
index 4d27366..5edf60a 100755 (executable)
@@ -21,6 +21,7 @@ BuildRequires: pkgconfig(capi-content-media-content)
 BuildRequires: pkgconfig(capi-media-metadata-extractor)
 BuildRequires: pkgconfig(capi-system-info)
 Buildrequires: pkgconfig(storage)
+BuildRequires: pkgconfig(libsystemd-daemon)
 Requires(post): /usr/bin/vconftool
 
 %define upgrade_script_path /usr/share/upgrade/scripts
index 8f821dd..2b4d495 100755 (executable)
@@ -1893,8 +1893,6 @@ mtp_err_t _hutil_construct_object_entry_prop_list(mtp_uint32 store_id,
        g_free(alb_buf);
 #endif /* MTP_SUPPORT_ALBUM_ART */
        *obj_ptr = obj;
-       if (obj_info != NULL)
-               _entity_dealloc_obj_info(obj_info);
 
        return MTP_ERROR_NONE;
 
index fa549c8..0dbf921 100755 (executable)
@@ -390,14 +390,14 @@ void _handle_lock_status_notification(keynode_t *key, void *data)
                __send_events_from_device_to_pc(MTP_INTERNAL_STORE_ID,
                                PTP_EVENTCODE_STOREADDED, 0, 0);
 
-               media_content_connect();
+               _util_media_content_connect();
        } else if (MTP_PHONE_LOCK_ON == current_val) {
                _device_uninstall_storage(MTP_ADDREM_INTERNAL);
 
                __send_events_from_device_to_pc(MTP_INTERNAL_STORE_ID,
                                PTP_EVENTCODE_STOREREMOVED, 0, 0);
 
-               media_content_disconnect();
+               _util_media_content_disconnect();
        }
 
        return;
index 1d79d17..2f749a1 100755 (executable)
@@ -155,9 +155,9 @@ void _mtp_init(add_rem_store_t sel)
                mtp_int32 ret;
                char inter_path[MTP_MAX_PATHNAME_SIZE + 1] = { 0 };
 
-               ret = media_content_connect();
-               if (MEDIA_CONTENT_ERROR_NONE != ret) {
-                       ERR("media_content_connect() Fail(%d)", ret);
+               ret = _util_media_content_connect();
+               if (FALSE == ret) {
+                       ERR("media_content_connect() Fail");
                        goto MTP_INIT_FAIL;
                }
 
@@ -495,7 +495,7 @@ int main(int argc, char *argv[])
        if (MTP_ERROR_NONE != ret) {
                ERR("_main_init() Fail(%d)", ret);
                _eh_deregister_notification_callbacks();
-               media_content_disconnect();
+               _util_media_content_disconnect();
                return MTP_ERROR_GENERAL;
        }
        DBG("MTP UID = [%u] and GID = [%u]\n", getuid(), getgid());
index a039945..273fd13 100755 (executable)
 #include "mtp_fs.h"
 #include <storage/storage.h>
 #include <sys/stat.h>
+#include <systemd/sd-login.h>
+#include <sys/types.h>
+//#include <grp.h>
+#include <media_content_internal.h>
+#include <pwd.h>
 
 static phone_state_t g_ph_status = { 0 };
 
@@ -346,43 +351,94 @@ static bool _util_device_external_supported_cb(int storage_id, storage_type_e ty
 void _util_get_external_path(char *external_path)
 {
        int error = STORAGE_ERROR_NONE;
+
        error = storage_foreach_device_supported(_util_device_external_supported_cb, external_path);
 
        if (error != STORAGE_ERROR_NONE) {
                ERR("get external storage path Fail");
-               strncpy(external_path, MTP_EXTERNAL_PATH_CHAR, strlen(MTP_EXTERNAL_PATH_CHAR));
+               if (external_path != NULL)
+                       strncpy(external_path, MTP_EXTERNAL_PATH_CHAR, strlen(MTP_EXTERNAL_PATH_CHAR) + 1);
        }
 }
-
-static bool _util_device_internal_supported_cb(int storage_id, storage_type_e type,
-       storage_state_e state, const char *path, void *user_data)
+uid_t _util_get_active_user()
 {
-       char *storage_path = (char *)user_data;
+       uid_t *active_user_list = NULL;
+       uid_t active_user = 0;
+       int user_cnt = 0;
 
-       //DBG("storage id: %d, path: %s", storage_id, path);
+       user_cnt = sd_get_active_uids(&active_user_list);
 
-       if (type == STORAGE_TYPE_INTERNAL && path != NULL) {
-               strncpy(storage_path, path, strlen(path));
-               //DBG("internal storage path : %s", storage_path);
-
-               if (storage_get_root_directory(storage_id, &storage_path) != STORAGE_ERROR_NONE) {
-                       ERR("get internal storage path Fail");
-                       return FALSE;
-               } else {
-                       //DBG("get internal storage path : %s", storage_path);
-               }
+       if (user_cnt <= 0) {
+               ERR("Active user not exists : %d", user_cnt);
+
+               if (active_user_list != NULL)
+                       free(active_user_list);
+
+               return -1;
        }
 
-       return TRUE;
+       if (active_user_list == NULL) {
+               ERR("active_user_list is NULL");
+               return -1;
+       }
+
+       active_user = active_user_list[0];
+
+       DBG("Active UID : %d", active_user);
+
+       free(active_user_list);
+
+       if (active_user <= 0) {
+               ERR("UID is not proper value : %d", active_user);
+               return -1;
+       }
+
+       return active_user;
 }
 
 void _util_get_internal_path(char *internal_path)
 {
-       int error = STORAGE_ERROR_NONE;
-       error = storage_foreach_device_supported(_util_device_internal_supported_cb, internal_path);
+       struct passwd *pwd;
+       uid_t active_user = 0;
+       char *active_name = NULL;
 
-       if (error != STORAGE_ERROR_NONE) {
-               ERR("get internal storage path Fail");
-               strncpy(internal_path, MTP_STORE_PATH_CHAR, strlen(MTP_STORE_PATH_CHAR));
+       active_user = _util_get_active_user();
+       pwd = getpwuid(active_user);
+       active_name = pwd->pw_name;
+
+       if (active_name == NULL) {
+               ERR("active_name is NULL");
+               strncpy(internal_path, MTP_USER_DIRECTORY, strlen(MTP_USER_DIRECTORY) + 1);
+               return;
        }
+
+       if (internal_path != NULL) {
+               strncpy(internal_path, MTP_INTERNAL_PATH_CHAR, strlen(MTP_INTERNAL_PATH_CHAR) + 1);
+               strncat(internal_path, active_name, strlen(active_name) + 1);
+               strncat(internal_path, "/media", 7);
+       }
+
+       ERR("internal path is %s", internal_path);
 }
+
+mtp_bool _util_media_content_connect()
+{
+       mtp_int32 ret = 0;
+       uid_t active_user = 0;
+
+       active_user = _util_get_active_user();
+
+       ret = media_content_connect_with_uid(active_user);
+       if (ret != MEDIA_CONTENT_ERROR_NONE) {
+               ERR("media_content_connect() failed : %d", ret);
+               return FALSE;
+       }
+
+       return TRUE;
+}
+
+void _util_media_content_disconnect()
+{
+       media_content_disconnect();
+}
+