+int _media_content_check_dir(const char *path)
+{
+ DIR *dp = NULL;
+ char *real = NULL;
+ char *origin = NULL;
+#ifndef _USE_TVPD_MODE
+ char result_path[MAX_PATH_LEN] = {0, };
+#endif
+ dp = opendir(path);
+ if (dp == NULL) {
+ if (errno == EACCES || errno == EPERM) {
+ media_content_stderror("open dir fail");
+ media_content_sec_error("path [%s]", path);
+ return MEDIA_CONTENT_ERROR_PERMISSION_DENIED;
+ } else {
+ media_content_stderror("open dir fail");
+ media_content_sec_error("path [%s]", path);
+ return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
+ }
+ }
+
+ closedir(dp);
+
+ /* Check symbolic link directory */
+ real = realpath(path, NULL);
+ /* Get trimmed path */
+ _media_util_trim_path(path, &origin);
+
+#ifdef _USE_TVPD_MODE
+ if (g_strcmp0(real, origin) != 0) {
+ media_content_error("symbolic link(directory)");
+ media_content_sec_debug("path[%s] real[%s]", origin, real);
+ SAFE_FREE(real);
+ SAFE_FREE(origin);
+ return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
+ }
+#else
+ if (g_str_has_prefix(real, MEDIA_SHARE_PATH)) {
+ /* If shared dirctory, it should be change path to TZ_USER_SHARE from realpath */
+ snprintf(result_path, MAX_PATH_LEN, "%s%s", tzplatform_getenv(TZ_USER_MEDIASHARED), real + strlen(MEDIA_SHARE_PATH));
+ if (g_strcmp0(result_path, origin) != 0) {
+ media_content_error("symbolic link(directory)");
+ media_content_sec_debug("path[%s] real[%s]", origin, real);
+ SAFE_FREE(real);
+ SAFE_FREE(origin);
+ return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
+ }
+ } else {
+ if (g_strcmp0(real, origin) != 0) {
+ media_content_error("symbolic link(directory)");
+ media_content_sec_debug("path[%s] real[%s]", origin, real);
+ SAFE_FREE(real);
+ SAFE_FREE(origin);
+ return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
+ }
+ }
+#endif
+
+ SAFE_FREE(real);
+ SAFE_FREE(origin);
+
+ return MEDIA_CONTENT_ERROR_NONE;
+}
+
+