Remove media-util-internal.h
[platform/core/multimedia/media-server.git] / lib / media-util-cynara.c
old mode 100755 (executable)
new mode 100644 (file)
index 7fb8aaf..f0f4c9c
@@ -3,8 +3,6 @@
  *
  * Copyright (c) 2015 Samsung Electronics Co., Ltd. All rights reserved.
  *
- * Contact: Yong Yeon Kim <yy9875.kim@samsung.com>
- *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
 #include <media-util-cynara.h>
 #include <media-util-dbg.h>
 #include <media-util-err.h>
-#include <media-util-internal.h>
 
 #include <cynara-client.h>
 #include <cynara-session.h>
 #include <cynara-error.h>
 #include <cynara-creds-socket.h>
 
-/* this definition is missing in glibc headers (version 2.21). It was introduced in kernel version 2.6.17 */
-#ifndef SCM_SECURITY
-#define SCM_SECURITY 0x03
-#endif
-
 static cynara *_cynara = NULL;
 static cynara_configuration *_p_conf = NULL;
 G_LOCK_DEFINE_STATIC(cynara_mutex);
@@ -103,25 +95,17 @@ int ms_cynara_receive_untrusted_message(int sockfd, ms_comm_msg_s *recv_msg, ms_
                return MS_MEDIA_ERR_INVALID_PARAMETER;
 
        if ((recv_msg_size = read(sockfd, recv_msg, sizeof(ms_comm_msg_s))) < 0) {
-               if (errno == EWOULDBLOCK) {
-                       MSAPI_DBG_ERR("Timeout. Can't try any more");
-                       return MS_MEDIA_ERR_SOCKET_RECEIVE_TIMEOUT;
-               } else {
-                       MSAPI_DBG_ERR("recv failed");
-                       return MS_MEDIA_ERR_SOCKET_RECEIVE;
-               }
+               MSAPI_DBG_STRERROR("recv failed");
+               return MS_MEDIA_ERR_IPC;
        }
 
-       MSAPI_DBG_SLOG("receive msg from P[%d] T[%d] M[%.*s] S[%.*s]", recv_msg->pid, recv_msg->msg_type, MAX_MSG_SIZE, recv_msg->msg, MS_UUID_SIZE, recv_msg->storage_id);
+       MSAPI_RETVM_IF(!ms_ipc_is_valid_msg(recv_msg->msg), MS_MEDIA_ERR_IPC, "Invalid msg");
 
-       if (strlen(recv_msg->msg) == 0 || strlen(recv_msg->msg) >= MAX_MSG_SIZE) {
-               MSAPI_DBG_ERR("IPC message is wrong. message size is %d", strlen(recv_msg->msg));
-               return MS_MEDIA_ERR_INVALID_IPC_MESSAGE;
-       }
+       MSAPI_DBG_SLOG("receive msg from P[%d] T[%d] M[%.*s] S[%.*s]", recv_msg->pid, recv_msg->msg_type, MAX_MSG_SIZE, recv_msg->msg, MS_UUID_SIZE, recv_msg->storage_id);
 
        if (strlen(recv_msg->storage_id) >= MS_UUID_SIZE) {
-               MSAPI_DBG_ERR("IPC message is wrong. storage_id size is %d", strlen(recv_msg->storage_id));
-               return MS_MEDIA_ERR_INVALID_IPC_MESSAGE;
+               MSAPI_DBG_ERR("IPC message is wrong. storage_id size is over MS_UUID_SIZE");
+               return MS_MEDIA_ERR_IPC;
        }
 
        ret = cynara_creds_socket_get_pid(sockfd, &(credentials->pid));
@@ -131,69 +115,23 @@ int ms_cynara_receive_untrusted_message(int sockfd, ms_comm_msg_s *recv_msg, ms_
        MSAPI_RETVM_IF(ret != 0, MS_MEDIA_ERR_INTERNAL, "[CYNARA]Failed to get uid");
 
        ret = cynara_creds_socket_get_client(sockfd, CLIENT_METHOD_SMACK, &(credentials->smack));
-       MSAPI_RETVM_IF(ret != 0, MS_MEDIA_ERR_INTERNAL, "[CYNARA]Failed to get smack");
-
-//     MSAPI_DBG_ERR("cynara_creds_info : P[%d]U[%s]S[%s]", credentials->pid, credentials->uid, credentials->smack);
-
-       return MS_MEDIA_ERR_NONE;
-}
-
-int ms_cynara_receive_untrusted_message_thumb(int sockfd, thumbMsg *recv_msg, ms_peer_credentials *credentials)
-{
-       int ret = 0;
-       int header_size = 0;
-       int recv_msg_size = 0;
-       unsigned char *buf = NULL;
-
-       if (!recv_msg || !credentials)
-               return MS_MEDIA_ERR_INVALID_PARAMETER;
-
-       header_size = sizeof(thumbMsg) - sizeof(unsigned char *);
-       MS_MALLOC(buf, header_size);
-
-       if ((recv_msg_size = recv(sockfd, buf, header_size, 0)) < 0) {
-               if (errno == EWOULDBLOCK) {
-                       MSAPI_DBG_ERR("Timeout. Can't try any more");
-                       MS_SAFE_FREE(buf);
-                       return MS_MEDIA_ERR_SOCKET_RECEIVE_TIMEOUT;
-               } else {
-                       MSAPI_DBG_ERR("recv failed");
-                       MS_SAFE_FREE(buf);
-                       return MS_MEDIA_ERR_SOCKET_RECEIVE;
+       if (ret != 0) {
+               MSAPI_DBG_ERR("[CYNARA]Failed to get smack");
+               if (credentials->uid) {
+                       free(credentials->uid);
+                       credentials->uid = NULL;
                }
-       }
-
-       memcpy(recv_msg, buf, header_size);
-       MS_SAFE_FREE(buf);
-
-       if (strlen(recv_msg->org_path) == 0 || strlen(recv_msg->org_path) >= MAX_FILEPATH_LEN) {
-               MSAPI_DBG_ERR("org_path size is invlid[%d]", strlen(recv_msg->org_path));
-               return MS_MEDIA_ERR_INVALID_IPC_MESSAGE;
-       }
 
-       if (strlen(recv_msg->dst_path) >= MAX_FILEPATH_LEN) {
-               MSAPI_DBG_ERR("dst_path size is invlid[%d]", strlen(recv_msg->dst_path));
-               return MS_MEDIA_ERR_INVALID_IPC_MESSAGE;
+               return MS_MEDIA_ERR_INTERNAL;
        }
 
-       ret = cynara_creds_socket_get_pid(sockfd, &(credentials->pid));
-       MSAPI_RETVM_IF(ret != 0, MS_MEDIA_ERR_INTERNAL, "[CYNARA]Failed to get pid");
-
-       ret = cynara_creds_socket_get_user(sockfd, USER_METHOD_UID, &(credentials->uid));
-       MSAPI_RETVM_IF(ret != 0, MS_MEDIA_ERR_INTERNAL, "[CYNARA]Failed to get uid");
-
-       ret = cynara_creds_socket_get_client(sockfd, CLIENT_METHOD_SMACK, &(credentials->smack));
-       MSAPI_RETVM_IF(ret != 0, MS_MEDIA_ERR_INTERNAL, "[CYNARA]Failed to get smack");
-
-//     MSAPI_DBG_ERR("cynara_creds_info : P[%d]U[%s]S[%s]", credentials->pid, credentials->uid, credentials->smack);
-
        return MS_MEDIA_ERR_NONE;
 }
 
 int ms_cynara_check(const ms_peer_credentials *creds, const char *privilege)
 {
-       int result;
-       char *session;
+       int result = 0;
+       char *session = NULL;
 
        if (!creds || !privilege)
                return MS_MEDIA_ERR_INVALID_PARAMETER;
@@ -208,7 +146,9 @@ int ms_cynara_check(const ms_peer_credentials *creds, const char *privilege)
        if (result != CYNARA_API_ACCESS_ALLOWED)
                ms_cynara_dbg_err("cynara_check", result);
 
-       MS_SAFE_FREE(session);
+       if (session)
+               free(session);
+
        return result == CYNARA_API_ACCESS_ALLOWED ? MS_MEDIA_ERR_NONE : MS_MEDIA_ERR_PERMISSION_DENIED;
 }
 
@@ -218,11 +158,10 @@ int ms_cynara_enable_credentials_passing(int fd)
        int err;
 
        err = setsockopt(fd, SOL_SOCKET, SO_PASSSEC, &optval, sizeof(optval));
-       MSAPI_RETVM_IF(err != 0, MS_MEDIA_ERR_SOCKET_INTERNAL, "Failed to set SO_PASSSEC socket option");
+       MSAPI_RETVM_IF(err != 0, MS_MEDIA_ERR_IPC, "Failed to set SO_PASSSEC socket option");
 
        err = setsockopt(fd, SOL_SOCKET, SO_PASSCRED, &optval, sizeof(optval));
-       MSAPI_RETVM_IF(err != 0, MS_MEDIA_ERR_SOCKET_INTERNAL, "Failed to set SO_PASSCRED socket option");
+       MSAPI_RETVM_IF(err != 0, MS_MEDIA_ERR_IPC, "Failed to set SO_PASSCRED socket option");
 
        return MS_MEDIA_ERR_NONE;
 }
-