2 * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
23 #include <sys/smack.h>
30 #include <csr-content-screening.h>
31 #include <thumbnail_util.h>
32 #include <image_util.h>
34 #include "MsgStorageTypes.h"
36 #include "MsgException.h"
37 #include "MsgUtilFile.h"
38 #include "MsgMmsTypes.h"
39 #include "MsgInternalTypes.h"
40 #include "MsgDrmWrapper.h"
50 void thumbnail_completed_cb(thumbnail_util_error_e error, const char *request_id,
51 int thumb_width, int thumb_height,
52 unsigned char *thumb_data, int thumb_size, void *user_data)
59 MSG_WARN("dstPath is NULL");
65 MSG_DEBUG("=================[RESULT]");
66 MSG_DEBUG("error_code [%d]", error);
67 MSG_DEBUG("request id [%s]", request_id);
68 MSG_DEBUG("width [%d], height [%d]", thumb_width, thumb_height);
69 MSG_DEBUG("size [%d]", thumb_size);
72 ret = image_util_encode_jpeg(thumb_data, thumb_width, thumb_height, IMAGE_UTIL_COLORSPACE_BGRA8888, 100, (char *)user_data);
73 if (ret != IMAGE_UTIL_ERROR_NONE)
74 MSG_WARN("image_util_encode_jpeg() is failed");
82 /*==================================================================================================
83 FUNCTION IMPLEMENTATION
84 ==================================================================================================*/
85 bool MakeThumbnail(char *srcPath, char *dstPath)
87 if (srcPath == NULL || dstPath == NULL) {
88 MSG_SEC_DEBUG("Invalid Param src = %p, dst = %p", srcPath, dstPath);
92 if (MsgAccessFile(srcPath, R_OK) == false) {
93 MSG_SEC_DEBUG("not exist source file [%s]", srcPath);
101 int ret = THUMBNAIL_UTIL_ERROR_NONE;
104 thumbnail_util_create(&thumb_h);
105 thumbnail_util_set_path(thumb_h, srcPath);
107 ret = thumbnail_util_extract(thumb_h, thumbnail_completed_cb, dstPath, &req_id);
108 thumbnail_util_destroy(thumb_h);
114 if (ret != THUMBNAIL_UTIL_ERROR_NONE) {
115 MSG_ERR("thumbnail_util_extract is failed");
120 time_ret = g_cv.timedwait(g_mx.pMsgMutex(), 5);
124 if (time_ret == ETIMEDOUT) {
125 MSG_ERR("@@ WAKE by timeout@@");
129 if (MsgAccessFile(dstPath, F_OK) == false) {
130 MSG_SEC_DEBUG("not exist result file [%s]", dstPath);
134 MSG_SEC_DEBUG("Make thumbnail: success [%s]", dstPath);
138 /* File operation wrappers */
139 FILE *MsgOpenFile(const char *filepath, const char *opt)
141 if (!filepath || !opt) {
142 MSG_FATAL("Null parameter");
146 MSG_SEC_DEBUG("[FILE] filepath : [%s], opt [%s]", filepath, opt);
151 pFile = fopen(filepath, opt);
152 MSG_DEBUG("[FILE] pFile [%p]", pFile);
153 } catch (exception &e) {
154 MSG_FATAL("%s", e.what());
161 void MsgCloseFile(FILE *pFile)
164 MSG_FATAL("NULL parameter");
168 MSG_DEBUG("[FILE] pFile [%p]", pFile);
172 } catch (exception &e) {
173 MSG_FATAL("%s", e.what());
177 int MsgFseek(FILE *pFile, long int offset, int origin)
180 MSG_FATAL("pFile NULL");
186 MSG_DEBUG("[FILE] pFile [%p], offset [%d], origin [%d]", pFile, offset, origin);
189 ret = fseek(pFile, offset, origin); /* return 0, if success. */
190 } catch (exception &e) {
191 MSG_FATAL("%s", e.what());
198 size_t MsgWriteFile(const char *pData, size_t size, size_t count, FILE *pFile)
200 if (!pData || !pFile) {
201 MSG_FATAL("pData or pFile NULL");
207 MSG_DEBUG("[FILE] pData [%p], size [%d], count [%d], pFile [%p]", pData, size, count, pFile);
210 nWrite = fwrite(pData, size, count, pFile);
211 } catch (exception &e) {
212 MSG_FATAL("%s", e.what());
218 size_t MsgReadFile(void *pData, size_t size, size_t count, FILE *pFile)
220 if (!pData || !pFile) {
221 MSG_FATAL("pData or pFile NULL");
228 nRead = fread(pData, size, count, pFile);
229 } catch (exception &e) {
230 MSG_FATAL("%s", e.what());
236 long int MsgFtell(FILE *pFile)
239 MSG_FATAL("pFile NULL");
243 long int ret = -1L; /* -1L return if error occured. */
247 } catch (exception &e) {
248 MSG_FATAL("%s", e.what());
254 int MsgFflush(FILE *pFile)
257 MSG_FATAL("pFile NULL");
264 ret = fflush(pFile); /* return 0 if success */
265 } catch (exception &e) {
266 MSG_FATAL("%s", e.what());
272 int MsgFsync(FILE *pFile)
275 MSG_FATAL("pFile NULL");
282 ret = fdatasync(pFile->_fileno); /* return 0 if success */
283 } catch (exception &e) {
284 MSG_FATAL("%s", e.what());
290 bool MsgCreateFileName(char *pFileName)
292 if (pFileName == NULL) {
293 MSG_DEBUG("[ERROR] pFileName is NULL");
300 if (clock_gettime(CLOCK_REALTIME, &ts) < 0) {
301 MSG_DEBUG("clock_gettime() error: %s", g_strerror(errno));
305 /* Create Random Number */
306 srandom((unsigned int)ts.tv_nsec);
308 MSG_DEBUG("ts.tv_nsec : %d", ts.tv_nsec);
310 /* between 1 - 1000000000 */
311 snprintf(pFileName, MSG_FILENAME_LEN_MAX, "MSG_%lu.DATA", random()%1000000000+1);
312 } catch (exception& e) {
313 MSG_FATAL("%s", e.what());
321 bool MsgOpenAndReadFile(const char *pFileName, char **ppData, int *pDataSize)
323 if (!pFileName || !ppData || !pDataSize) {
324 MSG_ERR("Invalid params!! pFileName=%x, ppData=%x, pDataSize=%x", pFileName, ppData, pDataSize);
328 MSG_DEBUG("MsgOpenAndReadFile");
332 char fullPath[MAX_FULL_PATH_SIZE] = {0};
334 snprintf(fullPath, MAX_FULL_PATH_SIZE, "%s%s", MSG_IPC_DATA_PATH, pFileName);
335 MSG_SEC_DEBUG("open file name: %s", fullPath);
337 pFile = MsgOpenFile(fullPath, "rb");
340 MSG_DEBUG("File Open Error: %s", g_strerror(errno));
344 if (MsgFseek(pFile, 0L, SEEK_END) < 0) {
346 MSG_DEBUG("File Read Error: %s", g_strerror(errno));
350 int FileSize = MsgFtell(pFile);
353 MSG_DEBUG("Filesize is error : %d", FileSize);
359 *ppData = new char[FileSize+1];
360 memset(*ppData, 0x00, (FileSize+1));
362 if (MsgFseek(pFile, 0L, SEEK_SET) < 0) {
364 MSG_DEBUG("File seek Error: %s", g_strerror(errno));
368 if (MsgReadFile(*ppData, sizeof(char), FileSize, pFile) != (size_t)FileSize) {
370 MSG_DEBUG("File Read Error: %s", g_strerror(errno));
374 *pDataSize = FileSize;
382 bool MsgReadFileForDecode(FILE *pFile, char *pBuf, int length, int *nSize)
386 if (MsgFseek(pFile, 0L, SEEK_CUR) < 0) {
387 MSG_DEBUG("File Seek Error: %s", g_strerror(errno));
392 *nSize = MsgReadFile(pBuf, sizeof(char), length, pFile);
399 bool MsgWriteIpcFile(const char *pFileName, const char *pData, int DataSize)
402 MSG_DEBUG("NULL parameter, pFileName [%p], pData [%p]", pFileName, pData);
406 char fullPath[MAX_FULL_PATH_SIZE] = {0};
408 snprintf(fullPath, MAX_FULL_PATH_SIZE, "%s%s", MSG_IPC_DATA_PATH, pFileName);
410 FILE *pFile = MsgOpenFile(fullPath, "wb+");
413 MSG_DEBUG("File Open Error: %s", g_strerror(errno));
417 if (MsgFseek(pFile, 0L, SEEK_SET) < 0) {
419 MSG_DEBUG("File Seek Error: %s", g_strerror(errno));
423 if (MsgWriteFile(pData, sizeof(char), DataSize, pFile) != (size_t)DataSize) {
425 MSG_DEBUG("File Write Error: %s", g_strerror(errno));
435 int MsgReadSmilFile(const char *pFileName, char **ppData)
438 MSG_DEBUG("pFileName is NULL");
443 char fullPath[MAX_FULL_PATH_SIZE] = {0};
445 snprintf(fullPath, MAX_FULL_PATH_SIZE, "%s%s", MSG_SMIL_FILE_PATH, pFileName);
447 MSG_SEC_DEBUG("open file name: %s", fullPath);
449 FILE *pFile = MsgOpenFile(fullPath, "rb");
452 MSG_DEBUG("File Open Error: %s", g_strerror(errno));
456 if (MsgFseek(pFile, 0L, SEEK_END) < 0) {
458 MSG_DEBUG("File Seek Error: %s", g_strerror(errno));
462 int FileSize = MsgFtell(pFile);
465 MSG_DEBUG("Filesize is error : %d", FileSize);
470 *ppData = new char[FileSize + 1];
471 memset(*ppData, 0x00, (FileSize+1));
473 if (MsgFseek(pFile, 0L, SEEK_SET) < 0) {
475 MSG_DEBUG("File Sead Error: %s", g_strerror(errno));
479 if (MsgReadFile(*ppData, sizeof(char), FileSize, pFile) != (size_t)FileSize) {
481 MSG_DEBUG("File Read Error: %s", g_strerror(errno));
485 /* ppData[FileSize] = '\0'; */
494 bool MsgWriteSmilFile(const char *pFilePath, char *pData, int DataSize)
497 MSG_DEBUG("pFilePath is NULL");
502 if (mkdir(MSG_SMIL_FILE_PATH, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) < 0) {
503 if (errno == EEXIST) {
504 MSG_SEC_DEBUG("The %s already exists", MSG_SMIL_FILE_PATH);
506 MSG_SEC_DEBUG("Error while mkdir %s", MSG_SMIL_FILE_PATH);
511 FILE *pFile = MsgOpenFile(pFilePath, "wb+");
514 MSG_DEBUG("File Open Error: %s", g_strerror(errno));
518 if (MsgFseek(pFile, 0L, SEEK_SET) < 0) {
520 MSG_DEBUG("File Seek Error: %s", g_strerror(errno));
524 if (MsgWriteFile(pData, sizeof(char), DataSize, pFile) != (size_t)DataSize) {
526 MSG_DEBUG("File Write Error: %s", g_strerror(errno));
537 void MsgDeleteFile(const char *pFileName)
540 MSG_FATAL("pFileName is NULL");
544 if (strlen(pFileName) == 0) {
545 MSG_FATAL("pFileName has zero length");
549 char fullPath[MAX_FULL_PATH_SIZE] = {0};
552 snprintf(fullPath, MAX_FULL_PATH_SIZE, "%s%s", MSG_IPC_DATA_PATH, pFileName);
554 MSG_SEC_DEBUG("%s", fullPath);
556 if (remove(fullPath) != 0)
557 MSG_SEC_ERR("File Delete Error [%s]: %s", fullPath, g_strerror(errno));
558 } catch (exception &e) {
559 MSG_FATAL("%s", e.what());
564 void MsgDeleteSmilFile(const char *pFileName)
567 MSG_FATAL("pFileName NULL");
572 char fullPath[MAX_FULL_PATH_SIZE] = {0};
574 snprintf(fullPath, MAX_FULL_PATH_SIZE, "%s%s", MSG_SMIL_FILE_PATH, pFileName);
576 if (remove(fullPath) != 0)
577 MSG_SEC_ERR("File Delete Error [%s]: %s", fullPath, g_strerror(errno));
578 } catch (exception &e) {
579 MSG_FATAL("%s", e.what());
584 bool MsgGetFileSize(const char *pFilePath, int *nSize)
587 MSG_FATAL("pFileName NULL");
593 pFile = MsgOpenFile(pFilePath, "rb");
596 MSG_DEBUG("File Open error: %s", g_strerror(errno));
600 if (MsgFseek(pFile, 0L, SEEK_END) < 0) {
602 MSG_FATAL("File Read Error: %s", g_strerror(errno));
606 *nSize = MsgFtell(pFile);
614 FILE *MsgOpenMMSFile(char *pFileName)
619 MSG_DEBUG("pFileName NULL: %s", g_strerror(errno));
623 len = strlen(pFileName);
625 for (int i = 0; i < len; i++) {
626 switch (pFileName[i]) {
633 MSG_SEC_DEBUG("pFileName = %s", pFileName);
635 char fullPath[MAX_FULL_PATH_SIZE+1] = {0};
637 snprintf(fullPath, MAX_FULL_PATH_SIZE+1, "%s.mms", pFileName);
639 FILE *pFile = MsgOpenFile(fullPath, "wb+");
642 MSG_ERR("File Open Error: %s", g_strerror(errno));
646 if (MsgFseek(pFile, 0L, SEEK_CUR) < 0) {
648 MSG_ERR("File Read Error: %s", g_strerror(errno));
656 bool MsgWriteDataFromEncodeBuffer(FILE *pFile, char *pInBuffer, int *pPtr, int maxLen, int *pOffset )
658 if (!pFile || !pPtr || !pInBuffer || !pOffset) {
659 MSG_FATAL(" NULL parameter passed");
663 MSG_DEBUG("MsgWriteDataFromEncodeBuffer:");
664 MSG_DEBUG("pInBuffer %x", pInBuffer);
665 MSG_DEBUG("pPtr %d", (*pPtr));
666 MSG_DEBUG("before to fwite %x", pFile);
668 if (MsgWriteFile(pInBuffer, sizeof(char), (*pPtr), pFile) != (size_t)(*pPtr)) {
669 MSG_FATAL("MsgWriteFile failed");
673 MSG_DEBUG("after to fwite \n");
677 memset(pInBuffer, 0, maxLen);
681 if (MsgFseek(pFile, 0L, SEEK_END) < 0) {
682 MSG_FATAL("MsgFseek failed");
686 *pOffset = MsgFtell(pFile);
688 if (*pOffset == -1L) {
689 MSG_FATAL("MsgFtell failed");
697 bool MsgOpenCreateAndOverwriteFile(char *pFullPath, char *pBuff, int TotalLength)
701 if ((pFile = MsgOpenFile(pFullPath, "wb+")) == NULL) {
702 MSG_FATAL("MsgOpenFile errer");
706 if (MsgWriteFile(pBuff, sizeof(char), TotalLength, pFile) != (size_t)TotalLength) {
711 MsgFsync(pFile); /* file is written to device immediately, it prevents missing file data from unexpected power off */
719 char *MsgOpenAndReadMmsFile(const char *szFilePath, int offset, int size, int *npSize)
725 if (szFilePath == NULL) {
726 MSG_ERR("szFilePath id NULL");
732 pFile = MsgOpenFile(szFilePath, "rb");
735 MSG_ERR("Can't open file: %s", g_strerror(errno));
740 if (MsgGetFileSize(szFilePath, & readSize) == false) {
741 MSG_DEBUG("MsgGetFileSize: failed");
747 /* restore Kies backup data size greater than FM_READ_WRITE_BUFFER_MAX */
749 if (readSize > FM_READ_WRITE_BUFFER_MAX) {
750 MSG_DEBUG("MsgOpenAndReadMmsFile: File size tried to read too big");
755 pData = (char *)calloc(1, readSize + 1);
756 if ( NULL == pData ) {
757 MSG_ERR("pData MemAlloc Fail : %s", g_strerror(errno) );
761 if (MsgFseek(pFile, offset, SEEK_SET) < 0) {
762 MSG_ERR("FmSeekFile failed : %s", g_strerror(errno) );
766 *npSize = MsgReadFile(pData, sizeof(char), readSize, pFile);
772 *(pData + (*npSize)) = '\0';
793 /* it is equivalent to "rm -rf pDirPath" */
794 int MsgRmRf(char *pDirPath)
796 struct dirent *d = NULL;
800 dir = opendir(pDirPath);
803 MSG_FATAL("error opendir: %s", g_strerror(errno));
807 int size = strlen(pDirPath) + 256;
809 char *path = (char*)malloc(size);
812 MSG_DEBUG("path is NULL");
819 for (readdir_r(dir, &entry, &d); d != NULL; readdir_r(dir, &entry, &d)) {
820 if (d->d_type == DT_DIR) {
821 snprintf(path, size, "%s/%s", pDirPath, d->d_name);
823 if ((strcmp(".", d->d_name) == 0) || (strcmp("..", d->d_name) == 0))
828 if (rmdir(path) != 0) {
834 MSG_FATAL("error rmdir: %s", g_strerror(errno));
839 snprintf(path, size, "%s/%s", pDirPath, d->d_name);
841 if (MsgDrmIsDrmFile(path))
842 MsgDrmUnregisterFile(path);
844 if (remove(path) != 0) {
850 MSG_FATAL("error remove: %s", g_strerror(errno));
867 int MsgGetFileSize(const char *pFileName)
869 struct stat file_stat;
871 if (lstat(pFileName, &file_stat)) {
872 MSG_FATAL("error lstat: %s", g_strerror(errno));
876 return file_stat.st_size;
880 /* it is equivalent to "du dir_path" */
881 unsigned int MsgDu(const char *pDirPath)
883 struct dirent *d = NULL;
887 dir = opendir(pDirPath);
890 MSG_FATAL("error opendir: %s", g_strerror(errno));
894 int size = strlen(pDirPath) + 256;
895 char *path = (char*)malloc(size);
903 unsigned int totalFileSize = 0;
905 for (readdir_r(dir, &entry, &d); d != NULL; readdir_r(dir, &entry, &d)) {
906 if(d->d_type == DT_DIR) {
907 snprintf(path, size, "%s/%s", pDirPath, d->d_name);
909 if ((strcmp(".", d->d_name) == 0) || (strcmp("..", d->d_name) == 0))
912 unsigned int dirSize = MsgDu(path);
915 MSG_FATAL("error MsgDu");
921 totalFileSize += dirSize;
923 snprintf(path, size, "%s/%s", pDirPath, d->d_name);
924 int fileSize = MsgGetFileSize(path);
927 MSG_FATAL("error MsgGetFileSize");
933 totalFileSize += fileSize;
942 return totalFileSize;
946 bool MsgAppendFile(const char *pFilePath, const char *pData, int DataSize)
949 MSG_FATAL("NULL check error, pFileName %p, pData %p", pFilePath, pData);
953 char fullPath[MAX_FULL_PATH_SIZE] = {0};
955 snprintf(fullPath, MAX_FULL_PATH_SIZE, "%s", pFilePath);
957 FILE *pFile = MsgOpenFile(fullPath, "a+");
960 MSG_FATAL("File Open Error: %s", g_strerror(errno));
964 if (MsgFseek(pFile, 0L, SEEK_CUR) < 0) {
966 MSG_FATAL("File Sead Error: %s", g_strerror(errno));
970 if (MsgWriteFile(pData, sizeof(char), DataSize, pFile) != (size_t)DataSize) {
972 MSG_FATAL("File Write Error: %s", g_strerror(errno));
976 MsgFsync(pFile); /*file is written to device immediately, it prevents missing file data from unexpected power off */
984 struct dirent *d = NULL;
988 dir = opendir(MSG_DATA_PATH);
991 MSG_FATAL("error opendir: %s", g_strerror(errno));
995 /* Remove temporal Mms folder */
996 for (readdir_r(dir, &entry, &d); d != NULL; readdir_r(dir, &entry, &d)) {
997 if (d->d_type == DT_DIR) {
998 if ((strcmp(".", d->d_name) == 0) || (strcmp("..", d->d_name) == 0))
1001 if(strstr(d->d_name, ".dir") != NULL) {
1002 char filePath[MSG_FILEPATH_LEN_MAX] = {0, };
1003 snprintf(filePath, MSG_FILEPATH_LEN_MAX, "%s%s", MSG_DATA_PATH, d->d_name);
1015 /* mode : R_OK, W_OK, X_OK, or the existence test F_OK. */
1016 bool MsgAccessFile(const char *filepath, int mode)
1019 if (filepath == NULL) {
1020 MSG_DEBUG("filepath is NULL");
1024 MSG_SEC_DEBUG("request access path = %s, mode = %d", filepath, mode);
1026 ret = access(filepath, mode);
1030 MSG_DEBUG("Fail to access file, ret = %d", ret);
1038 bool MsgChmod(const char *filepath, int mode)
1041 struct stat lstat_info;
1042 struct stat fstat_info;
1045 if (lstat(filepath, &lstat_info) == -1) {
1046 MSG_SEC_DEBUG("No such file as [%s].", filepath);
1050 fd = open(filepath, O_RDONLY);
1053 MSG_SEC_DEBUG("Fail to open [%s].", filepath);
1057 if (fstat(fd, &fstat_info) == -1) {
1058 MSG_SEC_DEBUG("Fail to fstat [%s].", filepath);
1063 if (lstat_info.st_mode == fstat_info.st_mode &&
1064 lstat_info.st_ino == fstat_info.st_ino &&
1065 lstat_info.st_dev == fstat_info.st_dev) {
1066 if (fchmod(fd, mode) < 0) {
1067 MSG_SEC_DEBUG("Fail to fchmod [%s].", filepath);
1079 bool MsgChown(const char *filepath, int uid, int gid)
1081 struct stat lstat_info;
1082 struct stat fstat_info;
1085 if (lstat(filepath, &lstat_info) == -1) {
1086 MSG_SEC_INFO("No such file as [%s].", filepath);
1090 fd = open(filepath, O_RDONLY);
1093 MSG_SEC_INFO("Fail to open [%s].", filepath);
1097 if (fstat(fd, &fstat_info) == -1) {
1098 MSG_SEC_INFO("Fail to fstat [%s].", filepath);
1103 if (lstat_info.st_mode == fstat_info.st_mode &&
1104 lstat_info.st_ino == fstat_info.st_ino &&
1105 lstat_info.st_dev == fstat_info.st_dev) {
1106 if (fchown(fd, uid, gid) < 0) {
1107 MSG_SEC_INFO("Fail to fchown [%s].", filepath);
1117 bool MsgCreateFile(const char *pFilePath, char *pData, int DataSize)
1120 MSG_DEBUG("pFilePath is NULL");
1124 FILE *pFile = MsgOpenFile(pFilePath, "wb+");
1126 if (pFile == NULL) {
1127 MSG_ERR("File Open Error: %s", g_strerror(errno));
1131 if (MsgFseek(pFile, 0L, SEEK_SET) < 0) {
1132 MsgCloseFile(pFile);
1133 MSG_ERR("File Seek Error: %s", g_strerror(errno));
1137 if (MsgWriteFile(pData, sizeof(char), DataSize, pFile) != (size_t)DataSize) {
1138 MsgCloseFile(pFile);
1139 MSG_ERR("File Write Error: %s", g_strerror(errno));
1145 MsgCloseFile(pFile);
1150 char *MsgGetDirName(char *file_path)
1152 return g_path_get_dirname(file_path);
1156 char *MsgGetFileName(char *file_path)
1158 return g_path_get_basename(file_path);
1162 int MsgCheckFilepathSmack(const char *app_smack_label, char *file_path)
1164 int err = MSG_SUCCESS;
1166 char *path_smack_label = NULL;
1167 char *dir_smack_label = NULL;
1168 char *dir_name = NULL;
1170 if (!file_path || file_path[0] == '\0') {
1175 if (stat(file_path, &st) != 0) {
1176 MSG_SEC_ERR("stat(%s, &st) != 0", file_path);
1177 return MSG_ERR_PERMISSION_DENIED;
1179 if (S_ISDIR(st.st_mode)) {
1180 MSG_ERR("S_ISDIR(st.st_mode)");
1181 return MSG_ERR_INVALID_PARAMETER;
1184 dir_name = MsgGetDirName(file_path);
1185 if (!dir_name || !g_strcmp0(dir_name, file_path)) {
1186 MSG_SEC_ERR("!dir_name || !g_strcmp0(dir_name, %s)", file_path);
1187 err = MSG_ERR_INVALID_PARAMETER;
1191 smack_getlabel(dir_name, &dir_smack_label, SMACK_LABEL_ACCESS);
1192 if (dir_smack_label == NULL) {
1193 MSG_ERR("smack_getlabel failed (dir_smack_label)");
1194 err = MSG_ERR_PERMISSION_DENIED;
1198 if (smack_have_access(app_smack_label, dir_smack_label, "RX") < 1) {
1199 MSG_ERR("smack_have_access failed (dir_smack_label)");
1200 err = MSG_ERR_PERMISSION_DENIED;
1204 smack_getlabel(file_path, &path_smack_label, SMACK_LABEL_ACCESS);
1205 if (path_smack_label == NULL) {
1206 MSG_ERR("smack_getlabel failed (path_smack_label)");
1207 err = MSG_ERR_PERMISSION_DENIED;
1211 if (smack_have_access(app_smack_label, path_smack_label, "R") < 1) {
1212 MSG_ERR("smack_have_access failed (path_smack_label)");
1213 err = MSG_ERR_PERMISSION_DENIED;
1217 MSG_DEBUG("smack_have_access pass successfully");
1220 MSG_FREE(path_smack_label);
1221 MSG_FREE(dir_smack_label);
1227 void MsgGetMimeType(char *filePath, char *mimeType, int size)
1229 aul_get_mime_from_file(filePath, mimeType, size);
1233 int MsgTcsScanFile(const char *filepath, int *bLevel)
1236 csr_cs_context_h csr_handle = NULL;
1237 csr_cs_malware_h detected = NULL;
1239 int ret_b_level = -1;
1241 if (MsgAccessFile(filepath, R_OK) == false) {
1242 MSG_SEC_DEBUG("not exist source file [%s]", filepath);
1246 MSG_SEC_DEBUG("Scanning file name : %s\n", filepath);
1248 ret = csr_cs_context_create(&csr_handle);
1249 if (ret != CSR_ERROR_NONE) {
1250 MSG_DEBUG("csr_cs_context_create error: err = %d\n", ret);
1254 ret = csr_cs_scan_file(csr_handle, filepath, &detected);
1255 if (ret == CSR_ERROR_NONE) {
1257 csr_cs_severity_level_e severity;
1260 ret = csr_cs_malware_get_severity(detected, &severity);
1261 if (ret != CSR_ERROR_NONE) {
1262 MSG_DEBUG("csr_cs_malware_get_severity error: err = %d\n", ret);
1265 ret = csr_cs_malware_get_name(detected, &name);
1266 if (ret != CSR_ERROR_NONE) {
1267 MSG_DEBUG("csr_cs_malware_get_name error: err = %d\n", ret);
1270 MSG_SEC_DEBUG(" +-- Malware Name: [%s]\n", name);
1271 MSG_DEBUG(" +-- Malware Severity class: %d\n", severity);
1273 ret_b_level = (int)severity;
1281 MSG_DEBUG("csr_cs_scan_file fail: err = %d\n", ret);
1284 ret = csr_cs_context_destroy(csr_handle);
1285 if (ret != CSR_ERROR_NONE) {
1286 MSG_DEBUG("csr_cs_context_destroy error: err = %d\n", ret);
1290 *bLevel = ret_b_level;