summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMinje Ahn <minje.ahn@samsung.com>2015-08-10 02:29:14 (GMT)
committerMinje ahn <minje.ahn@samsung.com>2015-08-12 10:15:03 (GMT)
commit7c8a2282af2fbdaeca8d2251980f4fca3afedb37 (patch)
tree4b17d77b3c23a0a344159b48015751dbcebd8c39
parent82be84757b2b156b477391816506aa63ab7e0211 (diff)
downloadlibmedia-thumbnail-7c8a2282af2fbdaeca8d2251980f4fca3afedb37.zip
libmedia-thumbnail-7c8a2282af2fbdaeca8d2251980f4fca3afedb37.tar.gz
libmedia-thumbnail-7c8a2282af2fbdaeca8d2251980f4fca3afedb37.tar.bz2
Change-Id: I2e96f30ebf2a71f0af673f19be422c43de6e8703 Signed-off-by: Minje Ahn <minje.ahn@samsung.com>
-rw-r--r--CMakeLists.txt1
-rw-r--r--packaging/libmedia-thumbnail.spec12
-rwxr-xr-xserver/include/thumb-server-internal.h2
-rwxr-xr-xserver/thumb-server-internal.c143
-rwxr-xr-xserver/thumb-server.c6
-rwxr-xr-xsrc/include/ipc/media-thumb-ipc.h4
-rwxr-xr-xsrc/include/util/media-thumb-debug.h3
-rwxr-xr-xsrc/ipc/media-thumb-ipc.c59
8 files changed, 110 insertions, 120 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 6f74a89..7eb108f 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -60,6 +60,7 @@ ADD_DEFINITIONS("-DVENDOR=\"${VENDOR}\"")
ADD_DEFINITIONS("-DPACKAGE=\"${PACKAGE}\"")
ADD_DEFINITIONS("-DPACKAGE_NAME=\"${PKGNAME}\"")
ADD_DEFINITIONS("-DPREFIX=\"${PREFIX}\"")
+ADD_DEFINITIONS("-D_GNU_SOURCE")
#ADD_DEFINITIONS("-D_PERFORMANCE_CHECK_")
SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -Wl,--hash-style=both")
diff --git a/packaging/libmedia-thumbnail.spec b/packaging/libmedia-thumbnail.spec
index f953bed..2b618d7 100644
--- a/packaging/libmedia-thumbnail.spec
+++ b/packaging/libmedia-thumbnail.spec
@@ -1,5 +1,5 @@
Name: libmedia-thumbnail
-Summary: Media thumbnail service library for multimedia applications.
+Summary: Media thumbnail service library for multimedia applications
Version: 0.1.82
Release: 0
Group: Multimedia/Libraries
@@ -26,24 +26,24 @@ BuildRequires: pkgconfig(sqlite3)
BuildRequires: pkgconfig(db-util)
%description
-Description: Media thumbnail service library for multimedia applications.
+Description: Media thumbnail service library for multimedia applications
%package devel
-Summary: Media thumbnail service library for multimedia applications. (development)
+Summary: Media thumbnail service library for multimedia applications (development)
Requires: %{name} = %{version}-%{release}
Group: Development/Libraries
%description devel
-Description: Media thumbnail service library for multimedia applications. (development)
+Description: Media thumbnail service library for multimedia applications (development)
%package -n media-thumbnail-server
-Summary: Thumbnail generator.
+Summary: Thumbnail generator
Requires: %{name} = %{version}-%{release}
Group: Development/Libraries
%description -n media-thumbnail-server
-Description: Media Thumbnail Server.
+Description: Media Thumbnail Server
%prep
diff --git a/server/include/thumb-server-internal.h b/server/include/thumb-server-internal.h
index ac9a8ab..0e16c74 100755
--- a/server/include/thumb-server-internal.h
+++ b/server/include/thumb-server-internal.h
@@ -68,6 +68,6 @@ int _thumbnail_get_raw_data(const char *origin_path,
int _media_thumb_process(thumbMsg *req_msg, thumbMsg *res_msg, uid_t uid);
-int _media_thumb_process_raw(thumbMsg *req_msg, thumbMsg *res_msg, thumbRawAddMsg *res_raw_msg);
+int _media_thumb_process_raw(thumbMsg *req_msg, thumbMsg *res_msg);
#endif /*_THUMB_DAEMON_INTERNAL_H_*/
diff --git a/server/thumb-server-internal.c b/server/thumb-server-internal.c
index c2f32c7..362326e 100755
--- a/server/thumb-server-internal.c
+++ b/server/thumb-server-internal.c
@@ -19,7 +19,6 @@
*
*/
- #define _GNU_SOURCE
#include "thumb-server-internal.h"
#include "media-thumb-util.h"
#include "media-thumb-debug.h"
@@ -42,6 +41,7 @@
#define THUMB_DEFAULT_WIDTH 320
#define THUMB_DEFAULT_HEIGHT 240
#define THUMB_BLOCK_SIZE 512
+#define THUMB_ROOT_UID "0"
static __thread char **arr_path;
static __thread uid_t *arr_uid;
@@ -52,6 +52,7 @@ GMainLoop *g_thumb_server_mainloop; // defined in thumb-server.c as extern
gboolean _thumb_server_send_msg_to_agent(int msg_type);
void _thumb_daemon_stop_job();
+static gboolean _thumb_server_send_deny_message(int sockfd);
gboolean _thumb_daemon_start_jobs(gpointer data)
{
@@ -180,11 +181,11 @@ int _thumb_daemon_process_job(thumbMsg *req_msg, thumbMsg *res_msg, uid_t uid)
return err;
}
-static int __thumb_daemon_process_job_raw(thumbMsg *req_msg, thumbMsg *res_msg, thumbRawAddMsg *res_raw_msg)
+static int __thumb_daemon_process_job_raw(thumbMsg *req_msg, thumbMsg *res_msg)
{
int err = MS_MEDIA_ERR_NONE;
- err = _media_thumb_process_raw(req_msg, res_msg, res_raw_msg);
+ err = _media_thumb_process_raw(req_msg, res_msg);
if (err != MS_MEDIA_ERR_NONE) {
if (err != MS_MEDIA_ERR_FILE_NOT_EXIST) {
thumb_warn("_media_thumb_process is failed: %d, So use default thumb", err);
@@ -333,16 +334,17 @@ gboolean _thumb_server_read_socket(GIOChannel *src,
{
struct sockaddr_un client_addr;
unsigned int client_addr_len;
+
thumbMsg recv_msg;
thumbMsg res_msg;
- thumbRawAddMsg res_raw_msg;
+ ms_peer_credentials credentials;
int sock = -1;
- int header_size = 0;
+ int client_sock = -1;
memset((void *)&recv_msg, 0, sizeof(recv_msg));
memset((void *)&res_msg, 0, sizeof(res_msg));
- memset((void *)&res_raw_msg, 0, sizeof(res_raw_msg));
+ memset((void *)&credentials, 0, sizeof(credentials));
sock = g_io_channel_unix_get_fd(src);
if (sock < 0) {
@@ -350,13 +352,38 @@ gboolean _thumb_server_read_socket(GIOChannel *src,
return TRUE;
}
- header_size = sizeof(thumbMsg) - MAX_PATH_SIZE * 2 - sizeof(unsigned char *);
+ client_addr_len = sizeof(client_addr);
+
+ if ((client_sock = accept(sock, (struct sockaddr*)&client_addr, &client_addr_len)) < 0) {
+ thumb_stderror("accept failed : %s");
+ return TRUE;
+ }
+
+ if (ms_cynara_receive_untrusted_message_thumb(client_sock, &recv_msg, &credentials) != MS_MEDIA_ERR_NONE) {
+ thumb_err("ms_cynara_receive_untrusted_message_thumb failed");
+ close(client_sock);
+ return FALSE;
+ }
- if (_media_thumb_recv_udp_msg(sock, header_size, &recv_msg, &client_addr, &client_addr_len) < 0) {
- thumb_err("_media_thumb_recv_udp_msg failed");
+ if (recv_msg.msg_type == THUMB_REQUEST_KILL_SERVER && strncmp(credentials.uid, THUMB_ROOT_UID, strlen(THUMB_ROOT_UID)) != 0) {
+ thumb_err("Only root can send THUMB_REQUEST_KILL_SERVER request");
+ _thumb_server_send_deny_message(client_sock);
+ close(client_sock);
return TRUE;
+ }
+
+ if(recv_msg.msg_type != THUMB_REQUEST_KILL_SERVER) {
+ if (ms_cynara_check(&credentials, MEDIA_STORAGE_PRIVILEGE) != MS_MEDIA_ERR_NONE) {
+ thumb_err("Cynara denied access to process request");
+ _thumb_server_send_deny_message(client_sock);
+ close(client_sock);
+ return TRUE;
+ }
}
+ SAFE_FREE(credentials.smack);
+ SAFE_FREE(credentials.uid);
+
thumb_warn_slog("Received [%d] %s(%d) from PID(%d)", recv_msg.msg_type, recv_msg.org_path, strlen(recv_msg.org_path), recv_msg.pid);
if (recv_msg.msg_type == THUMB_REQUEST_ALL_MEDIA) {
@@ -364,7 +391,7 @@ gboolean _thumb_server_read_socket(GIOChannel *src,
_thumb_daemon_all_extract(recv_msg.uid);
g_idle_add(_thumb_daemon_process_queue_jobs, NULL);
} else if(recv_msg.msg_type == THUMB_REQUEST_RAW_DATA) {
- __thumb_daemon_process_job_raw(&recv_msg, &res_msg, &res_raw_msg);
+ __thumb_daemon_process_job_raw(&recv_msg, &res_msg);
} else if(recv_msg.msg_type == THUMB_REQUEST_KILL_SERVER) {
thumb_warn("received KILL msg from thumbnail agent.");
} else {
@@ -385,39 +412,27 @@ gboolean _thumb_server_read_socket(GIOChannel *src,
}
int buf_size = 0;
- int block_size = 0;
- int sent_size = 0;
+ int sending_block = 0;
+ int block_size = sizeof(res_msg) - MAX_FILEPATH_LEN*2 - sizeof(unsigned char *);
unsigned char *buf = NULL;
- _media_thumb_set_buffer_for_response(&res_msg, &buf, &buf_size);
-
- if (sendto(sock, buf, buf_size, 0, (struct sockaddr *)&client_addr, sizeof(client_addr)) != buf_size) {
- thumb_stderror("sendto failed");
- SAFE_FREE(buf);
- return TRUE;
- }
-
- thumb_warn_slog("Sent %s(%d)", res_msg.dst_path, strlen(res_msg.dst_path));
- SAFE_FREE(buf);
+ _media_thumb_set_buffer(&res_msg, &buf, &buf_size);
- //Add sendto_raw_data
- if(recv_msg.msg_type == THUMB_REQUEST_RAW_DATA) {
- _media_thumb_set_add_raw_data_buffer(&res_raw_msg, &buf, &buf_size);
- block_size = THUMB_BLOCK_SIZE;
- while(buf_size > 0) {
- if (buf_size < THUMB_BLOCK_SIZE) {
- block_size = buf_size;
- }
- if (sendto(sock, buf + sent_size, block_size, 0, (struct sockaddr *)&client_addr, sizeof(client_addr)) != block_size) {
- thumb_err("sendto failed: %s", strerror(errno));
- SAFE_FREE(buf);
- return TRUE;
- }
- sent_size += block_size;
- buf_size -= block_size;
+ while(buf_size > 0) {
+ if(buf_size < THUMB_BLOCK_SIZE) {
+ block_size = buf_size;
+ }
+ if (send(client_sock, buf+sending_block, block_size, 0) != block_size) {
+ thumb_stderror("sendto failed : %s");
+ }
+ sending_block += block_size;
+ buf_size -= block_size;
+ if(block_size < THUMB_BLOCK_SIZE) {
+ block_size = THUMB_BLOCK_SIZE;
}
- thumb_warn_slog("Sent [%s] additional data[%d]", res_msg.org_path, sent_size);
}
-
+ if(buf_size == 0) {
+ thumb_dbg_slog("Sent data(%d) from %s", res_msg.thumb_size, res_msg.org_path);
+ }
SAFE_FREE(buf);
if(recv_msg.msg_type == THUMB_REQUEST_KILL_SERVER) {
@@ -425,6 +440,8 @@ gboolean _thumb_server_read_socket(GIOChannel *src,
g_main_loop_quit(g_thumb_server_mainloop);
}
+ close(client_sock);
+
return TRUE;
}
@@ -436,7 +453,7 @@ gboolean _thumb_server_send_msg_to_agent(int msg_type)
ms_thumb_server_msg send_msg;
sock_info.port = MS_THUMB_COMM_PORT;
- if (ms_ipc_create_client_socket(MS_PROTOCOL_UDP, MS_TIMEOUT_SEC_10, &sock_info) < 0) {
+ if (ms_ipc_create_client_socket(MS_PROTOCOL_TCP, MS_TIMEOUT_SEC_10, &sock_info) < 0) {
thumb_err("ms_ipc_create_server_socket failed");
return FALSE;
}
@@ -447,9 +464,17 @@ gboolean _thumb_server_send_msg_to_agent(int msg_type)
serv_addr.sun_family = AF_UNIX;
strcpy(serv_addr.sun_path, "/var/run/media-server/media_ipc_thumbcomm.socket");
+
+ /* Connecting to the thumbnail server */
+ if (connect(sock, (struct sockaddr*)&serv_addr, sizeof(serv_addr)) < 0) {
+ thumb_stderror("connect");
+ ms_ipc_delete_client_socket(&sock_info);
+ return MS_MEDIA_ERR_SOCKET_CONN;
+ }
+
send_msg.msg_type = msg_type;
- if (sendto(sock, &send_msg, sizeof(ms_thumb_server_msg), 0, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) != sizeof(ms_thumb_server_msg)) {
+ if (send(sock, &send_msg, sizeof(ms_thumb_server_msg), 0) != sizeof(ms_thumb_server_msg)) {
thumb_stderror("sendto failed");
ms_ipc_delete_client_socket(&sock_info);
return FALSE;
@@ -462,6 +487,22 @@ gboolean _thumb_server_send_msg_to_agent(int msg_type)
return TRUE;
}
+static gboolean _thumb_server_send_deny_message(int sockfd)
+{
+ thumbMsg msg = {0};
+ int bytes_to_send = sizeof(msg) - sizeof(msg.org_path) - sizeof(msg.dst_path);
+
+ msg.msg_type = THUMB_RESPONSE;
+ msg.status = THUMB_FAIL;
+
+ if (send(sockfd, &msg, bytes_to_send, 0) != bytes_to_send) {
+ thumb_stderror("send failed");
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
gboolean _thumb_server_prepare_socket(int *sock_fd)
{
int sock;
@@ -474,11 +515,16 @@ gboolean _thumb_server_prepare_socket(int *sock_fd)
memset((void *)&res_msg, 0, sizeof(res_msg));
serv_port = MS_THUMB_DAEMON_PORT;
- if (ms_ipc_create_server_socket(MS_PROTOCOL_UDP, serv_port, &sock) < 0) {
+ if (ms_ipc_create_server_socket(MS_PROTOCOL_TCP, serv_port, &sock) < 0) {
thumb_err("ms_ipc_create_server_socket failed");
return FALSE;
}
+ if (ms_cynara_enable_credentials_passing(sock) != MS_MEDIA_ERR_NONE) {
+ thumb_err("ms_cynara_enable_credentials_passing failed");
+ return FALSE;
+ }
+
*sock_fd = sock;
return TRUE;
@@ -550,7 +596,7 @@ int _thumbnail_get_data(const char *origin_path,
}
if (!g_file_test
- (origin_path, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) {
+ (origin_path, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) {
thumb_err("Original path (%s) does not exist", origin_path);
return MS_MEDIA_ERR_INVALID_PARAMETER;
}
@@ -622,7 +668,7 @@ int _thumbnail_get_raw_data(const char *origin_path,
}
if (!g_file_test
- (origin_path, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) {
+ (origin_path, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) {
thumb_err("Original path (%s) does not exist", origin_path);
return MS_MEDIA_ERR_INVALID_PARAMETER;
}
@@ -846,7 +892,7 @@ DB_UPDATE:
}
int
-_media_thumb_process_raw(thumbMsg *req_msg, thumbMsg *res_msg, thumbRawAddMsg *res_raw_msg)
+_media_thumb_process_raw(thumbMsg *req_msg, thumbMsg *res_msg)
{
int err = MS_MEDIA_ERR_NONE;
unsigned char *data = NULL;
@@ -882,10 +928,9 @@ _media_thumb_process_raw(thumbMsg *req_msg, thumbMsg *res_msg, thumbRawAddMsg *r
res_msg->msg_type = THUMB_RESPONSE_RAW_DATA;
res_msg->thumb_width = thumb_w;
res_msg->thumb_height = thumb_h;
- res_raw_msg->thumb_size = thumb_size;
- res_raw_msg->thumb_data = malloc(thumb_size * sizeof(unsigned char));
- memcpy(res_raw_msg->thumb_data, data, thumb_size);
- res_msg->thumb_size = thumb_size + sizeof(thumbRawAddMsg) - sizeof(unsigned char*);
+ res_msg->thumb_size = thumb_size;
+ res_msg->thumb_data = malloc(thumb_size * sizeof(unsigned char));
+ memcpy(res_msg->thumb_data, data, thumb_size);
//thumb_dbg("Size : %d, W:%d, H:%d", thumb_size, thumb_w, thumb_h);
SAFE_FREE(data);
diff --git a/server/thumb-server.c b/server/thumb-server.c
index 3a9a113..8e191f5 100755
--- a/server/thumb-server.c
+++ b/server/thumb-server.c
@@ -58,6 +58,11 @@ int main(void)
GIOChannel *channel = NULL;
GMainContext *context = NULL;
+ if (ms_cynara_initialize() != MS_MEDIA_ERR_NONE) {
+ thumb_err("Cynara initialization failed");
+ return -1;
+ }
+
/* Set VCONFKEY_SYSMAN_MMC_FORMAT callback to get noti for SD card format */
err = vconf_notify_key_changed(VCONFKEY_SYSMAN_MMC_FORMAT, (vconf_callback_fn) _thumb_daemon_vconf_cb, NULL);
if (err == -1)
@@ -107,6 +112,7 @@ int main(void)
g_io_channel_unref(channel);
_thumb_daemon_finish_jobs();
g_main_loop_unref(g_thumb_server_mainloop);
+ ms_cynara_finish();
return 0;
}
diff --git a/src/include/ipc/media-thumb-ipc.h b/src/include/ipc/media-thumb-ipc.h
index 7251ed9..5eacf12 100755
--- a/src/include/ipc/media-thumb-ipc.h
+++ b/src/include/ipc/media-thumb-ipc.h
@@ -65,10 +65,6 @@ int _media_thumb_recv_udp_msg(int sock, int header_size, thumbMsg *msg, struct s
int _media_thumb_set_buffer(thumbMsg *req_msg, unsigned char **buf, int *buf_size);
-int _media_thumb_set_buffer_for_response(thumbMsg *req_msg, unsigned char **buf, int *buf_size);
-
-int _media_thumb_set_add_raw_data_buffer(thumbRawAddMsg *req_msg, unsigned char **buf, int *buf_size);
-
int _media_thumb_request(int msg_type,
const char *origin_path,
char *thumb_path,
diff --git a/src/include/util/media-thumb-debug.h b/src/include/util/media-thumb-debug.h
index 3044fc4..cafd9d2 100755
--- a/src/include/util/media-thumb-debug.h
+++ b/src/include/util/media-thumb-debug.h
@@ -69,8 +69,7 @@
#define ERR_BUF_LENGHT 256
#define thumb_stderror(fmt) do { \
char thumb_stderror_buffer[ERR_BUF_LENGHT] = {0,}; \
- strerror_r(errno, thumb_stderror_buffer, ERR_BUF_LENGHT); \
- LOGE(FONT_COLOR_RED fmt" : standard error [%s]", thumb_stderror_buffer); \
+ LOGE(FONT_COLOR_RED fmt" : standard error [%s]", strerror_r(errno, thumb_stderror_buffer, ERR_BUF_LENGHT)); \
} while (0)
#ifdef _USE_LOG_FILE_
diff --git a/src/ipc/media-thumb-ipc.c b/src/ipc/media-thumb-ipc.c
index 7920fe7..b10a5be 100755
--- a/src/ipc/media-thumb-ipc.c
+++ b/src/ipc/media-thumb-ipc.c
@@ -322,63 +322,6 @@ _media_thumb_set_buffer(thumbMsg *req_msg, unsigned char **buf, int *buf_size)
}
int
-_media_thumb_set_buffer_for_response(thumbMsg *req_msg, unsigned char **buf, int *buf_size)
-{
- if (req_msg == NULL || buf == NULL) {
- return MS_MEDIA_ERR_INVALID_PARAMETER;
- }
-
- int org_path_len = 0;
- int dst_path_len = 0;
- int size = 0;
- int header_size = 0;
-
- header_size = sizeof(thumbMsg) -(MAX_FILEPATH_LEN * 2) - sizeof(unsigned char *);
- org_path_len = req_msg->origin_path_size;
- dst_path_len = req_msg->dest_path_size;
-
- thumb_dbg("Basic Size : %d, org_path : %s[%d], dst_path : %s[%d]", header_size, req_msg->org_path, org_path_len, req_msg->dst_path, dst_path_len);
-
- size = header_size + org_path_len + dst_path_len;
- *buf = malloc(size);
- if (*buf == NULL) {
- *buf_size = 0;
- return 0;
- }
- memcpy(*buf, req_msg, header_size);
- memcpy((*buf)+header_size, req_msg->org_path, org_path_len);
- memcpy((*buf)+header_size + org_path_len, req_msg->dst_path, dst_path_len);
-
- *buf_size = size;
-
- return MS_MEDIA_ERR_NONE;
-}
-
-
-int
-_media_thumb_set_add_raw_data_buffer(thumbRawAddMsg *req_msg, unsigned char **buf, int *buf_size)
-{
- if (req_msg == NULL || buf == NULL) {
- return MS_MEDIA_ERR_INVALID_PARAMETER;
- }
- int thumb_len = 0;
- int size = 0;
- int header_size = 0;
-
- header_size = sizeof(thumbRawAddMsg);
- thumb_len = req_msg->thumb_size;
-
- size = header_size + thumb_len;
- *buf = malloc(size);
- memcpy(*buf, req_msg, header_size);
- memcpy((*buf)+header_size, req_msg->thumb_data, thumb_len);
-
- *buf_size = size;
-
- return MS_MEDIA_ERR_NONE;
-}
-
-int
_media_thumb_request(int msg_type, const char *origin_path, char *thumb_path, int max_length, media_thumb_info *thumb_info, uid_t uid)
{
int sock = -1;
@@ -389,7 +332,7 @@ _media_thumb_request(int msg_type, const char *origin_path, char *thumb_path, in
int pid;
sock_info.port = MS_THUMB_CREATOR_PORT;
- err = ms_ipc_create_client_socket(MS_PROTOCOL_TCP, MS_TIMEOUT_SEC_10, &sock_info);
+ err = ms_ipc_create_client_socket(MS_PROTOCOL_TCP, MS_TIMEOUT_SEC_10, &sock_info);
if (err != MS_MEDIA_ERR_NONE) {
thumb_err("ms_ipc_create_client_socket failed");
return err;