#include <unistd.h>
#include <fcntl.h>
#include <libgen.h>
+#include <dlfcn.h>
-#include <csr-content-screening.h>
#include <thumbnail_util.h>
#include <image_util.h>
#include <aul.h>
}
+#define PATH_LIBCSR_CLIENT "/usr/lib/libcsr-client.so.2"
+
MsgMutex g_mx;
MsgCndVar g_cv;
aul_get_mime_from_file(filePath, mimeType, size);
}
-
int MsgTcsScanFile(const char *filepath, int *bLevel)
{
MSG_BEGIN();
- csr_cs_context_h csr_handle = NULL;
- csr_cs_malware_h detected = NULL;
- int ret = 0;
- int ret_b_level = -1;
+
+ int (*_csr_cs_context_create)(void **handle);
+ int (*_csr_cs_scan_file)(void *handle, const char *filepath, void **malware);
+ int (*_csr_cs_context_destroy)(void *handle);
+ int (*_csr_cs_malware_get_severity)(void *malware, void *severity);
+ int (*_csr_cs_malware_get_name)(void *malware, char **name);
if (MsgAccessFile(filepath, R_OK) == false) {
MSG_SEC_DEBUG("not exist source file [%s]", filepath);
MSG_SEC_DEBUG("Scanning file name : %s\n", filepath);
- ret = csr_cs_context_create(&csr_handle);
- if (ret != CSR_ERROR_NONE) {
+ void *lib_handle = NULL;
+ lib_handle = dlopen(PATH_LIBCSR_CLIENT, RTLD_LAZY);
+ if (!lib_handle) {
+ MSG_ERR("Unable to open %s", PATH_LIBCSR_CLIENT);
+ return 0;
+ }
+
+ _csr_cs_context_create = (int(*)(void**))dlsym(lib_handle, "csr_cs_context_create");
+ _csr_cs_scan_file = (int(*)(void*, const char*, void**))dlsym(lib_handle, "csr_cs_scan_file");
+ _csr_cs_context_destroy = (int(*)(void*))dlsym(lib_handle, "csr_cs_context_destroy");
+ _csr_cs_malware_get_severity = (int(*)(void*, void*))dlsym(lib_handle, "csr_cs_malware_get_severity");
+ _csr_cs_malware_get_name = (int(*)(void*, char**))dlsym(lib_handle, "csr_cs_malware_get_name");
+
+ int ret = 0;
+ if (!_csr_cs_context_create || !_csr_cs_scan_file || !_csr_cs_context_destroy
+ || !_csr_cs_malware_get_severity || !_csr_cs_malware_get_name) {
+ MSG_ERR("Failed to load CSR symbols");
+ if (lib_handle)
+ dlclose(lib_handle);
+ return -1;
+ }
+
+ void *csr_handle = NULL;
+ ret = _csr_cs_context_create(&csr_handle);
+ if (ret != 0) {
MSG_DEBUG("csr_cs_context_create error: err = %d\n", ret);
+ if (lib_handle)
+ dlclose(lib_handle);
return -1;
}
- ret = csr_cs_scan_file(csr_handle, filepath, &detected);
- if (ret == CSR_ERROR_NONE) {
- if (detected) {
- csr_cs_severity_level_e severity = CSR_CS_SEVERITY_LOW;
- char *name = NULL;
+ do {
+ void *detected = NULL;
+ ret = _csr_cs_scan_file(csr_handle, filepath, &detected);
+ if (ret != 0) {
+ MSG_DEBUG("csr_cs_scan_file fail: err = %d\n", ret);
+ break;
+ }
- ret = csr_cs_malware_get_severity(detected, &severity);
- if (ret != CSR_ERROR_NONE) {
- MSG_DEBUG("csr_cs_malware_get_severity error: err = %d\n", ret);
- }
+ if (NULL == detected) {
+ MSG_DEBUG("Nothing detected");
+ break;
+ }
- ret = csr_cs_malware_get_name(detected, &name);
- if (ret != CSR_ERROR_NONE) {
- MSG_DEBUG("csr_cs_malware_get_name error: err = %d\n", ret);
- }
+ int severity = 0x01; /* CSR_CS_SEVERITY_LOW */
+ ret = _csr_cs_malware_get_severity(detected, &severity);
+ if (ret != 0) {
+ MSG_DEBUG("csr_cs_malware_get_severity error: err = %d\n", ret);
+ }
+ MSG_DEBUG(" +-- Malware Severity class: %d\n", severity);
- MSG_SEC_DEBUG(" +-- Malware Name: [%s]\n", name);
- MSG_DEBUG(" +-- Malware Severity class: %d\n", severity);
+ char *name = NULL;
+ ret = _csr_cs_malware_get_name(detected, &name);
+ if (ret != 0) {
+ MSG_DEBUG("csr_cs_malware_get_name error: err = %d\n", ret);
+ }
+ MSG_SEC_DEBUG(" +-- Malware Name: [%s]\n", name);
- ret_b_level = (int)severity;
+ if (name)
+ free(name);
- if (name) {
- free(name);
- name = NULL;
- }
- }
- } else {
- MSG_DEBUG("csr_cs_scan_file fail: err = %d\n", ret);
- }
+ if (bLevel)
+ *bLevel = severity;
- ret = csr_cs_context_destroy(csr_handle);
- if (ret != CSR_ERROR_NONE) {
+ } while (0);
+
+ ret = _csr_cs_context_destroy(csr_handle);
+ if (ret != 0)
MSG_DEBUG("csr_cs_context_destroy error: err = %d\n", ret);
- }
- if (bLevel)
- *bLevel = ret_b_level;
+ if (lib_handle)
+ dlclose(lib_handle);
MSG_END();
-
return 0;
}
+
+