diff options
author | Jean-Benoit MARTIN <jean-benoit.martin@open.eurogiciel.org> | 2014-08-26 16:28:49 +0200 |
---|---|---|
committer | Jean-Benoit MARTIN <jean-benoit.martin@open.eurogiciel.org> | 2014-09-30 14:09:14 +0200 |
commit | 561e2cae46730cdbadf485dfa7ab449e60524bae (patch) | |
tree | 5d2127e248aac6750950cbd2352976729baa4bc7 /src | |
parent | 1b8cf739c37f1103b7fa613b788f0d5e32f5bad9 (diff) | |
download | libmedia-thumbnail-accepted/tizen_3.0.m14.3_ivi.tar.gz libmedia-thumbnail-accepted/tizen_3.0.m14.3_ivi.tar.bz2 libmedia-thumbnail-accepted/tizen_3.0.m14.3_ivi.zip |
Multiuser featuretizen_3.0.m14.3_ivi_releasetizen_3.0.2014.q3_common_releasesubmit/tizen_mobile/20141120.000000submit/tizen_ivi/20141007.222222submit/tizen_common/20141001.125034accepted/tizen/ivi/20141008.075209accepted/tizen/common/20141001.131249tizen_3.0.m14.3_ivitizen_3.0.2014.q3_commonaccepted/tizen_3.0.m14.3_iviaccepted/tizen_3.0.2014.q3_common
Use User UID to write or read into database
Use Unix socket
Fix-Tizen: TC-1482
Change-Id: I557a28de1650c9af1a30ef7d795d64464eaa2e8f
Signed-off-by: Jean-Benoit MARTIN <jean-benoit.martin@open.eurogiciel.org>
Diffstat (limited to 'src')
-rwxr-xr-x | src/include/ipc/media-thumb-ipc.h | 10 | ||||
-rwxr-xr-x | src/include/media-thumb-internal.h | 6 | ||||
-rwxr-xr-x | src/include/util/media-thumb-db.h | 5 | ||||
-rwxr-xr-x | src/include/util/media-thumb-util.h | 11 | ||||
-rwxr-xr-x | src/ipc/media-thumb-ipc.c | 94 | ||||
-rwxr-xr-x | src/media-thumb-internal.c | 16 | ||||
-rwxr-xr-x | src/media-thumbnail.c | 28 | ||||
-rwxr-xr-x | src/util/media-thumb-db.c | 26 | ||||
-rwxr-xr-x | src/util/media-thumb-util.c | 113 |
9 files changed, 242 insertions, 67 deletions
diff --git a/src/include/ipc/media-thumb-ipc.h b/src/include/ipc/media-thumb-ipc.h index ce81c01..1819af4 100755 --- a/src/include/ipc/media-thumb-ipc.h +++ b/src/include/ipc/media-thumb-ipc.h @@ -42,6 +42,7 @@ #include <unistd.h> #include <errno.h> #include <signal.h> +#include <sys/types.h> #ifndef _MEDIA_THUMB_IPC_H_ #define _MEDIA_THUMB_IPC_H_ @@ -83,6 +84,7 @@ typedef struct _thumbMsg{ media_thumb_type thumb_type; int status; int pid; + uid_t uid; int thumb_size; int thumb_width; int thumb_height; @@ -121,15 +123,17 @@ _media_thumb_request(int msg_type, const char *origin_path, char *thumb_path, int max_length, - media_thumb_info *thumb_info); + media_thumb_info *thumb_info, + uid_t uid); int _media_thumb_request_async(int msg_type, media_thumb_type thumb_type, const char *origin_path, - thumbUserData *userData); + thumbUserData *userData, + uid_t uid); int -_media_thumb_process(thumbMsg *req_msg, thumbMsg *res_msg); +_media_thumb_process(thumbMsg *req_msg, thumbMsg *res_msg, uid_t uid); #endif /*_MEDIA_THUMB_IPC_H_*/ diff --git a/src/include/media-thumb-internal.h b/src/include/media-thumb-internal.h index 0180a29..32427ca 100755 --- a/src/include/media-thumb-internal.h +++ b/src/include/media-thumb-internal.h @@ -69,13 +69,15 @@ _media_thumb_image(const char *origin_path, int thumb_width, int thumb_height, media_thumb_format format, - media_thumb_info *thumb_info); + media_thumb_info *thumb_info, + uid_t uid); int _media_thumb_video(const char *origin_path, int thumb_width, int thumb_height, media_thumb_format format, - media_thumb_info *thumb_info); + media_thumb_info *thumb_info, + uid_t uid); #endif /*_MEDIA_THUMB_INTERNAL_H_*/ diff --git a/src/include/util/media-thumb-db.h b/src/include/util/media-thumb-db.h index effd3f4..b29920a 100755 --- a/src/include/util/media-thumb-db.h +++ b/src/include/util/media-thumb-db.h @@ -51,7 +51,7 @@ sqlite3 *_media_thumb_db_get_handle(); int -_media_thumb_db_connect(); +_media_thumb_db_connect(uid_t uid); int _media_thumb_db_disconnect(); @@ -74,7 +74,8 @@ int _media_thumb_update_db(const char *origin_path, char *thumb_path, int width, - int height); + int height, + uid_t uid); #endif /*_MEDIA_THUMB_DB_H_*/ diff --git a/src/include/util/media-thumb-util.h b/src/include/util/media-thumb-util.h index 20c54bb..4fe33f8 100755 --- a/src/include/util/media-thumb-util.h +++ b/src/include/util/media-thumb-util.h @@ -43,10 +43,10 @@ #define THUMB_PATH_PHONE MEDIA_ROOT_PATH_INTERNAL /**< File path prefix of files stored in phone */ #define THUMB_PATH_MMC MEDIA_ROOT_PATH_SDCARD /**< File path prefix of files stored in mmc card */ -#define THUMB_PHONE_PATH tzplatform_mkpath(TZ_SYS_DATA, "file-manager-service/.thumb/phone") -#define THUMB_MMC_PATH tzplatform_mkpath(TZ_SYS_DATA, "file-manager-service/.thumb/mmc") +#define THUMB_PHONE_PATH tzplatform_mkpath(TZ_USER_DATA, "file-manager-service/.thumb/phone") +#define THUMB_MMC_PATH tzplatform_mkpath(TZ_USER_DATA, "file-manager-service/.thumb/mmc") -#define THUMB_DEFAULT_PATH tzplatform_mkpath(TZ_SYS_DATA, "file-manager-service/.thumb/thumb_default.png") +#define THUMB_DEFAULT_PATH tzplatform_mkpath(TZ_USER_DATA, "file-manager-service/.thumb/thumb_default.png") typedef enum { @@ -72,7 +72,7 @@ char int _media_thumb_get_hash_name(const char *file_full_path, - char *thumb_hash_path, size_t max_thumb_path); + char *thumb_hash_path, size_t max_thumb_path, uid_t uid); int _media_thumb_save_to_file_with_evas(unsigned char *data, @@ -141,7 +141,8 @@ int _thumbnail_get_data(const char *origin_path, int *height, int *origin_width, int *origin_height, - int *alpha); + int *alpha, + uid_t uid); #endif /*_MEDIA_THUMB_UTIL_H_*/ diff --git a/src/ipc/media-thumb-ipc.c b/src/ipc/media-thumb-ipc.c index 23f9960..84cc682 100755 --- a/src/ipc/media-thumb-ipc.c +++ b/src/ipc/media-thumb-ipc.c @@ -27,6 +27,10 @@ #include <fcntl.h> #include <string.h> #include <errno.h> +#include <grp.h> +#include <pwd.h> + +#define GLOBAL_USER 0 //#define tzplatform_getenv(TZ_GLOBAL) //TODO static __thread GQueue *g_request_queue = NULL; typedef struct { @@ -312,7 +316,7 @@ _media_thumb_set_buffer(thumbMsg *req_msg, unsigned char **buf, int *buf_size) } int -_media_thumb_request(int msg_type, media_thumb_type thumb_type, const char *origin_path, char *thumb_path, int max_length, media_thumb_info *thumb_info) +_media_thumb_request(int msg_type, media_thumb_type thumb_type, const char *origin_path, char *thumb_path, int max_length, media_thumb_info *thumb_info, uid_t uid) { int sock; #ifdef _USE_UDS_SOCKET_ @@ -360,10 +364,10 @@ _media_thumb_request(int msg_type, media_thumb_type thumb_type, const char *orig #ifdef _USE_MEDIA_UTIL_ #ifdef _USE_UDS_SOCKET_ - strcpy(serv_addr.sun_path, "/tmp/media_ipc_thumbcreator.dat"); + strcpy(serv_addr.sun_path, "/var/run/media-server/media_ipc_thumbcreator.socket"); #elif defined(_USE_UDS_SOCKET_TCP_) thumb_dbg(""); - strcpy(serv_addr.sun_path, "/tmp/media_ipc_thumbcreator.dat"); + strcpy(serv_addr.sun_path, "/var/run/media-server/media_ipc_thumbcreator.socket"); #else serv_addr.sin_port = htons(MS_THUMB_CREATOR_PORT); #endif @@ -390,6 +394,7 @@ _media_thumb_request(int msg_type, media_thumb_type thumb_type, const char *orig /* Set requset message */ req_msg.msg_type = msg_type; req_msg.thumb_type = thumb_type; + req_msg.uid = uid; strncpy(req_msg.org_path, origin_path, sizeof(req_msg.org_path)); req_msg.org_path[strlen(req_msg.org_path)] = '\0'; @@ -456,8 +461,65 @@ _media_thumb_request(int msg_type, media_thumb_type thumb_type, const char *orig return 0; } +static int _mkdir(const char *dir, mode_t mode) { + char tmp[256]; + char *p = NULL; + size_t len; + + snprintf(tmp, sizeof(tmp),"%s",dir); + len = strlen(tmp); + if(tmp[len - 1] == '/') + tmp[len - 1] = 0; + for(p = tmp + 1; *p; p++) + if(*p == '/') { + *p = 0; + mkdir(tmp, mode); + *p = '/'; + } + return mkdir(tmp, mode); +} + +static char* _media_thumb_get_default_path(uid_t uid) +{ + char *result_psswd = NULL; + struct group *grpinfo = NULL; + if(uid == getuid()) + { + result_psswd = strdup(THUMB_DEFAULT_PATH); + grpinfo = getgrnam("users"); + if(grpinfo == NULL) { + thumb_err("getgrnam(users) returns NULL !"); + return NULL; + } + } + else + { + struct passwd *userinfo = getpwuid(uid); + if(userinfo == NULL) { + thumb_err("getpwuid(%d) returns NULL !", uid); + return NULL; + } + grpinfo = getgrnam("users"); + if(grpinfo == NULL) { + thumb_err("getgrnam(users) returns NULL !"); + return NULL; + } + // Compare git_t type and not group name + if (grpinfo->gr_gid != userinfo->pw_gid) { + thumb_err("UID [%d] does not belong to 'users' group!", uid); + return NULL; + } + asprintf(&result_psswd, "%s/data/file-manager-service/.thumb/phone", userinfo->pw_dir); + } + + /* create dir */ + _mkdir(result_psswd,S_IRWXU | S_IRWXG | S_IRWXO); + + return result_psswd; +} + int -_media_thumb_process(thumbMsg *req_msg, thumbMsg *res_msg) +_media_thumb_process(thumbMsg *req_msg, thumbMsg *res_msg, uid_t uid) { int err = -1; unsigned char *data = NULL; @@ -486,7 +548,7 @@ _media_thumb_process(thumbMsg *req_msg, thumbMsg *res_msg) thumb_path[0] = '\0'; max_length = sizeof(res_msg->dst_path); - err = _media_thumb_db_connect(); + err = _media_thumb_db_connect(uid); if (err < 0) { thumb_err("_media_thumb_mb_svc_connect failed: %d", err); return MEDIA_THUMB_ERROR_DB; @@ -501,10 +563,10 @@ _media_thumb_process(thumbMsg *req_msg, thumbMsg *res_msg) return MEDIA_THUMB_ERROR_NONE; } else { if (strlen(thumb_path) == 0) { - err = _media_thumb_get_hash_name(origin_path, thumb_path, max_length); + err = _media_thumb_get_hash_name(origin_path, thumb_path, max_length,uid); if (err < 0) { thumb_err("_media_thumb_get_hash_name failed - %d\n", err); - strncpy(thumb_path, THUMB_DEFAULT_PATH, max_length); + strncpy(thumb_path, _media_thumb_get_default_path(uid), max_length); _media_thumb_db_disconnect(); return err; } @@ -517,10 +579,10 @@ _media_thumb_process(thumbMsg *req_msg, thumbMsg *res_msg) strncpy(thumb_path, req_msg->dst_path, max_length); } else if (msg_type == THUMB_REQUEST_ALL_MEDIA) { - err = _media_thumb_get_hash_name(origin_path, thumb_path, max_length); + err = _media_thumb_get_hash_name(origin_path, thumb_path, max_length,uid); if (err < 0) { thumb_err("_media_thumb_get_hash_name failed - %d\n", err); - strncpy(thumb_path, THUMB_DEFAULT_PATH, max_length); + strncpy(thumb_path, _media_thumb_get_default_path(uid), max_length); _media_thumb_db_disconnect(); return err; } @@ -528,20 +590,18 @@ _media_thumb_process(thumbMsg *req_msg, thumbMsg *res_msg) thumb_path[strlen(thumb_path)] = '\0'; } - thumb_dbg("Thumb path : %s", thumb_path); - if (g_file_test(thumb_path, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) { thumb_warn("thumb path already exists in file system.. remove the existed file"); _media_thumb_remove_file(thumb_path); } - err = _thumbnail_get_data(origin_path, thumb_type, thumb_format, &data, &thumb_size, &thumb_w, &thumb_h, &origin_w, &origin_h, &alpha); + err = _thumbnail_get_data(origin_path, thumb_type, thumb_format, &data, &thumb_size, &thumb_w, &thumb_h, &origin_w, &origin_h, &alpha, uid); if (err < 0) { thumb_err("_thumbnail_get_data failed - %d\n", err); SAFE_FREE(data); - strncpy(thumb_path, THUMB_DEFAULT_PATH, max_length); + strncpy(thumb_path, _media_thumb_get_default_path(uid), max_length); _media_thumb_db_disconnect(); return err; } @@ -576,7 +636,7 @@ _media_thumb_process(thumbMsg *req_msg, thumbMsg *res_msg) SAFE_FREE(data); if (msg_type == THUMB_REQUEST_DB_INSERT || msg_type == THUMB_REQUEST_ALL_MEDIA) - strncpy(thumb_path, THUMB_DEFAULT_PATH, max_length); + strncpy(thumb_path, _media_thumb_get_default_path(uid), max_length); _media_thumb_db_disconnect(); return err; @@ -603,7 +663,7 @@ _media_thumb_process(thumbMsg *req_msg, thumbMsg *res_msg) /* DB update if needed */ if (need_update_db == 1) { - err = _media_thumb_update_db(origin_path, thumb_path, res_msg->origin_width, res_msg->origin_height); + err = _media_thumb_update_db(origin_path, thumb_path, res_msg->origin_width, res_msg->origin_height, uid); if (err < 0) { thumb_err("_media_thumb_update_db failed : %d", err); } @@ -662,7 +722,7 @@ callback: } int -_media_thumb_request_async(int msg_type, media_thumb_type thumb_type, const char *origin_path, thumbUserData *userData) +_media_thumb_request_async(int msg_type, media_thumb_type thumb_type, const char *origin_path, thumbUserData *userData, uid_t uid) { int sock; #ifdef _USE_UDS_SOCKET_ @@ -752,6 +812,8 @@ _media_thumb_request_async(int msg_type, media_thumb_type thumb_type, const char req_msg.pid = pid; req_msg.msg_type = msg_type; req_msg.thumb_type = thumb_type; + req_msg.uid = uid; + strncpy(req_msg.org_path, origin_path, sizeof(req_msg.org_path)); req_msg.org_path[strlen(req_msg.org_path)] = '\0'; diff --git a/src/media-thumb-internal.c b/src/media-thumb-internal.c index 0feee8a..fc0ca00 100755 --- a/src/media-thumb-internal.c +++ b/src/media-thumb-internal.c @@ -169,7 +169,7 @@ _media_thumb_get_thumb_from_exif(ExifData *ed, int orientation, int required_width, int required_height, - media_thumb_info *thumb_info) + media_thumb_info *thumb_info, uid_t uid) { ExifEntry *entry; ExifIfd ifd; @@ -278,7 +278,7 @@ _media_thumb_get_thumb_from_exif(ExifData *ed, err = _media_thumb_get_hash_name(file_full_path, thumb_path, - sizeof(thumb_path)); + sizeof(thumb_path), uid); if (err < 0) { thumb_dbg("_media_thumb_get_hash_name failed\n"); SAFE_FREE(thumb); @@ -951,7 +951,8 @@ int _media_thumb_jpeg(const char *origin_path, int thumb_width, int thumb_height, media_thumb_format format, - media_thumb_info *thumb_info) + media_thumb_info *thumb_info, + uid_t uid) { int err = -1; ExifData *ed = NULL; @@ -970,7 +971,7 @@ int _media_thumb_jpeg(const char *origin_path, } /* Second, Get thumb from exif */ - err = _media_thumb_get_thumb_from_exif(ed, origin_path, orientation, thumb_width, thumb_height, thumb_info); + err = _media_thumb_get_thumb_from_exif(ed, origin_path, orientation, thumb_width, thumb_height, thumb_info, uid); if (err < 0) { thumb_dbg("_media_thumb_get_thumb_from_exif failed"); @@ -1021,7 +1022,7 @@ _media_thumb_image(const char *origin_path, int thumb_width, int thumb_height, media_thumb_format format, - media_thumb_info *thumb_info) + media_thumb_info *thumb_info, uid_t uid) { int err = -1; int image_type = 0; @@ -1045,7 +1046,7 @@ _media_thumb_image(const char *origin_path, if (image_type == IMG_CODEC_AGIF) { err = _media_thumb_agif(origin_path, &image_info, thumb_width, thumb_height, format, thumb_info); } else if (image_type == IMG_CODEC_JPEG) { - err = _media_thumb_jpeg(origin_path, thumb_width, thumb_height, format, thumb_info); + err = _media_thumb_jpeg(origin_path, thumb_width, thumb_height, format, thumb_info, uid); } else if (image_type == IMG_CODEC_PNG) { err = _media_thumb_png(origin_path, thumb_width, thumb_height, format, thumb_info); } else if (image_type == IMG_CODEC_GIF) { @@ -1095,7 +1096,8 @@ _media_thumb_video(const char *origin_path, int thumb_width, int thumb_height, media_thumb_format format, - media_thumb_info *thumb_info) + media_thumb_info *thumb_info, + uid_t uid) { int err = -1; diff --git a/src/media-thumbnail.c b/src/media-thumbnail.c index 420414e..c52c42a 100755 --- a/src/media-thumbnail.c +++ b/src/media-thumbnail.c @@ -28,7 +28,7 @@ #include <glib.h> -int thumbnail_request_from_db(const char *origin_path, char *thumb_path, int max_length) +int thumbnail_request_from_db(const char *origin_path, char *thumb_path, int max_length, uid_t uid) { int err = -1; //int need_update_db = 0; @@ -73,7 +73,7 @@ int thumbnail_request_from_db(const char *origin_path, char *thumb_path, int max } */ /* Request for thumb file to the daemon "Thumbnail generator" */ - err = _media_thumb_request(THUMB_REQUEST_DB_INSERT, MEDIA_THUMB_LARGE, origin_path, thumb_path, max_length, &thumb_info); + err = _media_thumb_request(THUMB_REQUEST_DB_INSERT, MEDIA_THUMB_LARGE, origin_path, thumb_path, max_length, &thumb_info, uid); if (err < 0) { thumb_err("_media_thumb_request failed : %d", err); //_media_thumb_db_disconnect(); @@ -93,7 +93,7 @@ int thumbnail_request_from_db(const char *origin_path, char *thumb_path, int max return MEDIA_THUMB_ERROR_NONE; } -int thumbnail_request_save_to_file(const char *origin_path, media_thumb_type thumb_type, const char *thumb_path) +int thumbnail_request_save_to_file(const char *origin_path, media_thumb_type thumb_type, const char *thumb_path, uid_t uid) { int err = -1; @@ -109,7 +109,7 @@ int thumbnail_request_save_to_file(const char *origin_path, media_thumb_type thu tmp_thumb_path[sizeof(tmp_thumb_path) - 1] = '\0'; /* Request for thumb file to the daemon "Thumbnail generator" */ - err = _media_thumb_request(THUMB_REQUEST_SAVE_FILE, thumb_type, origin_path, tmp_thumb_path, sizeof(tmp_thumb_path), &thumb_info); + err = _media_thumb_request(THUMB_REQUEST_SAVE_FILE, thumb_type, origin_path, tmp_thumb_path, sizeof(tmp_thumb_path), &thumb_info, uid); if (err < 0) { thumb_err("_media_thumb_request failed : %d", err); return err; @@ -118,7 +118,7 @@ int thumbnail_request_save_to_file(const char *origin_path, media_thumb_type thu return MEDIA_THUMB_ERROR_NONE; } -int thumbnail_request_from_db_with_size(const char *origin_path, char *thumb_path, int max_length, int *origin_width, int *origin_height) +int thumbnail_request_from_db_with_size(const char *origin_path, char *thumb_path, int max_length, int *origin_width, int *origin_height, uid_t uid) { int err = -1; //int need_update_db = 0; @@ -168,7 +168,7 @@ int thumbnail_request_from_db_with_size(const char *origin_path, char *thumb_pat } */ /* Request for thumb file to the daemon "Thumbnail generator" */ - err = _media_thumb_request(THUMB_REQUEST_DB_INSERT, MEDIA_THUMB_LARGE, origin_path, thumb_path, max_length, &thumb_info); + err = _media_thumb_request(THUMB_REQUEST_DB_INSERT, MEDIA_THUMB_LARGE, origin_path, thumb_path, max_length, &thumb_info, uid); if (err < 0) { thumb_err("_media_thumb_request failed : %d", err); //_media_thumb_db_disconnect(); @@ -182,7 +182,7 @@ int thumbnail_request_from_db_with_size(const char *origin_path, char *thumb_pat return MEDIA_THUMB_ERROR_NONE; } -int thumbnail_request_extract_all_thumbs(void) +int thumbnail_request_extract_all_thumbs(uid_t uid) { int err = -1; @@ -192,7 +192,7 @@ int thumbnail_request_extract_all_thumbs(void) char tmp_thumb_path[MAX_PATH_SIZE] = {0,}; /* Request for thumb file to the daemon "Thumbnail generator" */ - err = _media_thumb_request(THUMB_REQUEST_ALL_MEDIA, thumb_type, tmp_origin_path, tmp_thumb_path, sizeof(tmp_thumb_path), &thumb_info); + err = _media_thumb_request(THUMB_REQUEST_ALL_MEDIA, thumb_type, tmp_origin_path, tmp_thumb_path, sizeof(tmp_thumb_path), &thumb_info, uid); if (err < 0) { thumb_err("_media_thumb_request failed : %d", err); return err; @@ -201,7 +201,7 @@ int thumbnail_request_extract_all_thumbs(void) return MEDIA_THUMB_ERROR_NONE; } -int thumbnail_request_from_db_async(const char *origin_path, ThumbFunc func, void *user_data) +int thumbnail_request_from_db_async(const char *origin_path, ThumbFunc func, void *user_data, uid_t uid) { int err = -1; @@ -231,7 +231,7 @@ int thumbnail_request_from_db_async(const char *origin_path, ThumbFunc func, voi userData->user_data = user_data; /* Request for thumb file to the daemon "Thumbnail generator" */ - err = _media_thumb_request_async(THUMB_REQUEST_DB_INSERT, MEDIA_THUMB_LARGE, origin_path, userData); + err = _media_thumb_request_async(THUMB_REQUEST_DB_INSERT, MEDIA_THUMB_LARGE, origin_path, userData, uid); if (err < 0) { thumb_err("_media_thumb_request failed : %d", err); SAFE_FREE(userData); @@ -249,7 +249,7 @@ int _media_thumbnail_cancel_cb(int error_code, char* path, void* data) return MEDIA_THUMB_ERROR_NONE; } -int thumbnail_request_cancel_media(const char *origin_path) +int thumbnail_request_cancel_media(const char *origin_path, uid_t uid) { int err = -1; @@ -260,7 +260,7 @@ int thumbnail_request_cancel_media(const char *origin_path) return MEDIA_THUMB_ERROR_INVALID_PARAMETER; } - err = _media_thumb_request_async(THUMB_REQUEST_CANCEL_MEDIA, thumb_type, origin_path, NULL); + err = _media_thumb_request_async(THUMB_REQUEST_CANCEL_MEDIA, thumb_type, origin_path, NULL, uid); if (err < 0) { thumb_err("_media_thumb_request failed : %d", err); return err; @@ -269,7 +269,7 @@ int thumbnail_request_cancel_media(const char *origin_path) return MEDIA_THUMB_ERROR_NONE; } -int thumbnail_request_cancel_all() +int thumbnail_request_cancel_all(uid_t uid) { int err = -1; @@ -279,7 +279,7 @@ int thumbnail_request_cancel_all() char tmp_thumb_path[MAX_PATH_SIZE] = {0,}; /* Request for thumb file to the daemon "Thumbnail generator" */ - err = _media_thumb_request(THUMB_REQUEST_CANCEL_ALL, thumb_type, tmp_origin_path, tmp_thumb_path, sizeof(tmp_thumb_path), &thumb_info); + err = _media_thumb_request(THUMB_REQUEST_CANCEL_ALL, thumb_type, tmp_origin_path, tmp_thumb_path, sizeof(tmp_thumb_path), &thumb_info, uid); if (err < 0) { thumb_err("_media_thumb_request failed : %d", err); return err; diff --git a/src/util/media-thumb-db.c b/src/util/media-thumb-db.c index e3ca193..1ee9aa5 100755 --- a/src/util/media-thumb-db.c +++ b/src/util/media-thumb-db.c @@ -241,7 +241,8 @@ _media_thumb_get_thumb_path_from_db(sqlite3 *handle, int _media_thumb_update_thumb_path_to_db(sqlite3 *handle, const char *origin_path, - char *thumb_path) + char *thumb_path, + uid_t uid) { thumb_dbg(""); int err = -1; @@ -281,7 +282,7 @@ _media_thumb_update_thumb_path_to_db(sqlite3 *handle, if (err_msg) sqlite3_free(err_msg); #else - err = media_db_request_update_db(query_string); + err = media_db_request_update_db(query_string, uid); if (err < 0) { thumb_err("media_db_request_update_db failed : %d", err); return err; @@ -296,7 +297,8 @@ int _media_thumb_update_wh_to_db(sqlite3 *handle, const char *origin_path, int width, - int height) + int height, + uid_t uid) { thumb_dbg(""); int err = -1; @@ -333,7 +335,7 @@ _media_thumb_update_wh_to_db(sqlite3 *handle, if (err_msg) sqlite3_free(err_msg); #else - err = media_db_request_update_db(query_string); + err = media_db_request_update_db(query_string, uid); if (err < 0) { thumb_err("media_db_request_update_db failed : %d", err); return err; @@ -349,7 +351,8 @@ _media_thumb_update_thumb_path_wh_to_db(sqlite3 *handle, const char *origin_path, char *thumb_path, int width, - int height) + int height, + uid_t uid) { thumb_dbg(""); int err = -1; @@ -364,7 +367,7 @@ _media_thumb_update_thumb_path_wh_to_db(sqlite3 *handle, path_string = sqlite3_mprintf("%s", origin_path); query_string = sqlite3_mprintf(UPDATE_THUMB_WH_BY_PATH, thumb_path, width, height, path_string); - err = media_db_request_update_db(query_string); + err = media_db_request_update_db(query_string, uid); if (err < 0) { thumb_err("media_db_request_update_db failed : %d", err); return err; @@ -376,7 +379,7 @@ _media_thumb_update_thumb_path_wh_to_db(sqlite3 *handle, } int -_media_thumb_db_connect() +_media_thumb_db_connect(uid_t uid) { int err = -1; /* @@ -395,7 +398,7 @@ _media_thumb_db_connect() return err; } #else - err = media_db_connect(&db_handle); + err = media_db_connect(&db_handle,uid); if (err < 0) { thumb_err("media_db_connect failed: %d", err); db_handle = NULL; @@ -528,7 +531,8 @@ int _media_thumb_update_db(const char *origin_path, char *thumb_path, int width, - int height) + int height, + uid_t uid) { thumb_dbg(""); int err = -1; @@ -588,13 +592,13 @@ _media_thumb_update_db(const char *origin_path, } #else if (media_type == THUMB_IMAGE_TYPE && width > 0 && height > 0) { - err = _media_thumb_update_thumb_path_wh_to_db(db_handle, origin_path, thumb_path, width, height); + err = _media_thumb_update_thumb_path_wh_to_db(db_handle, origin_path, thumb_path, width, height,uid); if (err < 0) { thumb_err("_media_thumb_update_wh_to_db (%s) failed: %d", origin_path, err); return MEDIA_THUMB_ERROR_DB; } } else { - err = _media_thumb_update_thumb_path_to_db(db_handle, origin_path, thumb_path); + err = _media_thumb_update_thumb_path_to_db(db_handle, origin_path, thumb_path, uid); if (err < 0) { thumb_err("_media_thumb_update_thumb_path_to_db (%s) failed: %d", origin_path, err); return MEDIA_THUMB_ERROR_DB; diff --git a/src/util/media-thumb-util.c b/src/util/media-thumb-util.c index 0db4133..3f287bd 100755 --- a/src/util/media-thumb-util.c +++ b/src/util/media-thumb-util.c @@ -29,6 +29,10 @@ #include <Evas.h> #include <Ecore_Evas.h> +#include <grp.h> +#include <pwd.h> + +#define GLOBAL_USER 0 //#define tzplatform_getenv(TZ_GLOBAL) //TODO int _media_thumb_get_width(media_thumb_type thumb_type) { @@ -195,9 +199,103 @@ int _media_thumb_remove_file(const char *path) } } +static int _mkdir(const char *dir, mode_t mode) { + char tmp[256]; + char *p = NULL; + size_t len; + + snprintf(tmp, sizeof(tmp),"%s",dir); + len = strlen(tmp); + if(tmp[len - 1] == '/') + tmp[len - 1] = 0; + for(p = tmp + 1; *p; p++) + if(*p == '/') { + *p = 0; + mkdir(tmp, mode); + *p = '/'; + } + return mkdir(tmp, mode); +} + +static char* _media_thumb_mmc_get_path(uid_t uid) +{ + char *result_psswd = NULL; + struct group *grpinfo = NULL; + if(uid == getuid()) + { + result_psswd = strdup(THUMB_MMC_PATH); + grpinfo = getgrnam("users"); + if(grpinfo == NULL) { + thumb_err("getgrnam(users) returns NULL !"); + return NULL; + } + } + else + { + struct passwd *userinfo = getpwuid(uid); + if(userinfo == NULL) { + thumb_err("getpwuid(%d) returns NULL !", uid); + return NULL; + } + grpinfo = getgrnam("users"); + if(grpinfo == NULL) { + thumb_err("getgrnam(users) returns NULL !"); + return NULL; + } + // Compare git_t type and not group name + if (grpinfo->gr_gid != userinfo->pw_gid) { + thumb_err("UID [%d] does not belong to 'users' group!", uid); + return NULL; + } + asprintf(&result_psswd, "%s/data/file-manager-service/.thumb/mmc", userinfo->pw_dir); + } + + _mkdir(result_psswd,S_IRWXU | S_IRWXG | S_IRWXO); + + return result_psswd; +} + +static char* _media_thumb_phone_get_path(uid_t uid) +{ + char *result_psswd = NULL; + struct group *grpinfo = NULL; + if(uid == getuid()) + { + result_psswd = strdup(THUMB_PHONE_PATH); + grpinfo = getgrnam("users"); + if(grpinfo == NULL) { + thumb_err("getgrnam(users) returns NULL !"); + return NULL; + } + } + else + { + struct passwd *userinfo = getpwuid(uid); + if(userinfo == NULL) { + thumb_err("getpwuid(%d) returns NULL !", uid); + return NULL; + } + grpinfo = getgrnam("users"); + if(grpinfo == NULL) { + thumb_err("getgrnam(users) returns NULL !"); + return NULL; + } + // Compare git_t type and not group name + if (grpinfo->gr_gid != userinfo->pw_gid) { + thumb_err("UID [%d] does not belong to 'users' group!", uid); + return NULL; + } + asprintf(&result_psswd, "%s/data/file-manager-service/.thumb/phone", userinfo->pw_dir); + } + + _mkdir(result_psswd,S_IRWXU | S_IRWXG | S_IRWXO); + + return result_psswd; +} + int _media_thumb_get_hash_name(const char *file_full_path, - char *thumb_hash_path, size_t max_thumb_path) + char *thumb_hash_path, size_t max_thumb_path, uid_t uid) { char *hash_name; char *thumb_dir = NULL; @@ -215,11 +313,11 @@ _media_thumb_get_hash_name(const char *file_full_path, store_type = _media_thumb_get_store_type_by_path(file_full_path); if (store_type == THUMB_PHONE) { - thumb_dir = THUMB_PHONE_PATH; + thumb_dir = _media_thumb_phone_get_path(uid); } else if (store_type == THUMB_MMC) { - thumb_dir = THUMB_MMC_PATH; + thumb_dir = _media_thumb_mmc_get_path(uid); } else { - thumb_dir = THUMB_PHONE_PATH; + thumb_dir = _media_thumb_phone_get_path(uid); } hash_name = _media_thumb_generate_hash_name(file_full_path); @@ -303,7 +401,8 @@ int _thumbnail_get_data(const char *origin_path, int *height, int *origin_width, int *origin_height, - int *alpha) + int *alpha, + uid_t uid) { int err = -1; int thumb_width = -1; @@ -345,14 +444,14 @@ int _thumbnail_get_data(const char *origin_path, file_type = _media_thumb_get_file_type(origin_path); if (file_type == THUMB_IMAGE_TYPE) { - err = _media_thumb_image(origin_path, thumb_width, thumb_height, format, &thumb_info); + err = _media_thumb_image(origin_path, thumb_width, thumb_height, format, &thumb_info, uid); if (err < 0) { thumb_err("_media_thumb_image failed"); return err; } } else if (file_type == THUMB_VIDEO_TYPE) { - err = _media_thumb_video(origin_path, thumb_width, thumb_height, format, &thumb_info); + err = _media_thumb_video(origin_path, thumb_width, thumb_height, format, &thumb_info,uid); if (err < 0) { thumb_err("_media_thumb_image failed"); return err; |